A question about the fstream

B

blackkettle

The code is as follows:

#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;
}

After I compiled and built the code, a file named 714.exe was
generated.
In DOS, I input C>714 file and enter,

I thought the sentence "Write strings to disk, RETURN to stop" would
show up. However, it did not appear.
Only after I enter some sentences and enter twice would it come out.

I was wondering what is the problem.

Thank you very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fstream - write a file 3
problem with fstream 3
fstream and ofstream 2
fstream question 2
fstream vs ofstream 6
Understanding fstream seeking 2
fstream & parameters... 7
fstream question 3

Members online

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top