读文件的时候,出现奇怪的问题!
俺是初学VC.NET,写了下面一段代码来读文件:
FileStream * fs;
StreamReader * sr;
try{
fs = new FileStream( path, FileMode::Open );
sr = new StreamReader( fs );
}
catch( System::Exception * pe ){
Console::WriteLine( pe->ToString() );
}
int count = 0;
String * tempStr;
for( ; ; )
{
tempStr = sr->ReadLine();
count ++;
if( tempStr = 0 ) break;
Console::WriteLine( count.ToString() );
Console::WriteLine( tempStr );
tempStr = Console::ReadLine();
if( tempStr->Equals( S"q" ) || tempStr->Equals( S"Q" ) )
{
break;
}
}
sr->Close();
fs->Close();
但是txt文件里明明有内容,为什么没有显示出来呢?
没有任何错误提示!