一个关于 fstream的问题
代码如下:
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
main(int argc, char *argv[])
{
if(argc!=2)
{
cout<<"Usage:write <filename>\n";
return 1;
}
ofstream outf(argv[1]);
if(!outf)
{
cout<<"Cannot open output file.\n";
return 1;
}
cout<<"Write strings to disk, RETURN to stop\n";
char str[60];
do
{
cout<<":";
gets(str);
outf<<str<<endl;
}while(*str);
outf.close();
return 0;
}
我编译连接后,一个叫 714.exe的文件生成了。
我在DOS下敲入 C>714 file
然后回车。
我想应该会立刻显示 "Write strings to disk, RETURN to stop"。
可是没有出现。
当我输入好几句话后,回车两次,
"Write strings to disk, RETURN to stop" 才出现。
请问怎么解决这个问题。
万分感谢!