很奇怪的问题 改为ios_base::in 就可以了 不能ios_base::in|ios_base::app
否则打开错误 为什么??
main()
{
// 以输入和附加模式打开
fstream inOut("copyout", ios_base::in );
int cnt = 0; // 字节计数器
char ch;
while ( inOut.get( ch ) )
{
cout.put( ch ); // 在终端回显
++cnt;
if ( ch == '\n' ) {
inOut << cnt ;
inOut.put( ' ' ); // 空格
}
}
// 输出最终的字节数
inOut << cnt << endl;
cout << "[ " << cnt << " ]" << endl;
return 0;
}
???