CppReader.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- using namespace System;
- using namespace System::IO;
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(int argc, char* argv[])
- #endif
- {
- // Check for required arguments
- if (argc < 2)
- {
- Console::WriteLine(S"Usage: CppReader path");
- return 0;
- }
- String* path = new String(argv[1]);
- if (!File::Exists(path))
- {
- Console::WriteLine("Invalid filename!");
- return -1;
- }
- try
- {
- FileStream* fs = new FileStream(path, FileMode::Open);
- StreamReader* sr = new StreamReader(fs);
- int count = 0;
- for(;;)
- {
- String* line = sr->ReadLine();
- count++;
- // If there are no more lines, break out of the loop
- if (line == 0) break;
- Console::WriteLine(line);
- if (count % 20 == 0)
- {
- Console::Write("--more--");
- String* response = Console::ReadLine();
- if (response->Equals(S"q")) break;
- count = 0;
- }
- }
- Console::WriteLine("-- end --");
- }
- catch(System::Exception* pe)
- {
- Console::WriteLine(pe->ToString());
- }
- return 0;
- }