标题: About the usage of ifstream and ofstream [打印本页] 作者: Tonney8888 时间: 2004-08-20 15:56 标题: About the usage of ifstream and ofstream I have a TXT file with contents named test.txt as follow:
This is a test
444444
333333
good by!
I defined a ifstream variable named inFile and intialized with a string "test.txt", and I defined string outString and an ofstream variable named outFile with "output.txt" for initializing.I used the statements for coping the content of file test.txt into file output.txt as follow:
inFile >;>; outString;
outFile << outString;
but the content of the output.txt displayed as follow:
This is a test
Why? I need help.
Thank you!作者: aero 时间: 2004-08-20 16:16 标题: About the usage of ifstream and ofstream 接getchar的返回值的类型错了吧?
int,不是char。作者: whyglinux 时间: 2004-08-20 16:53 标题: About the usage of ifstream and ofstream 将程序做如下修改即可:
// inFile >;>; outString;
getline( inFile, outString );
// outFile << outString;
outFile << outString << "\n";
复制代码
以后要把问题描述清楚些(比如你给的结果就不正确,也不清楚你如何得到的。虽然可以猜出来)。最好贴上代码。作者: Tonney8888 时间: 2004-08-21 13:56 标题: About the usage of ifstream and ofstream sorry,我的程序是这样的:
ifstream inFile("test.txt"
inFile >;>; outString;
ofstream outFile("output.txt"
outFile << outString;
在test.txt文件中的内容如下:
This is a test
444444
333333
good by!
执行上述语句后,output.txt中的内容如下:
This is a test
没有使用getline()funtion.
Thank you!