[疑惑中]!!关于fstream与ostream的不解!!为什么出现这样的结果!!!
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void main(){
fstream f("a.txt");//使用fstream
f<<"i love you baby";
ifstream a("a.txt");
for(string str;a>>str;)
cout<<str;
cout<<endl;
}
结果:
Press any key to continue
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void main(){
ofstream f("a.txt");//使用ofstream
f<<"i love you baby";
ifstream a("a.txt");
for(string str;a>>str;)
cout<<str;
cout<<endl;
}
结果:
iloveyoubaby
Press any key to continue
为什么结果不同呢?
请明白人解释一下,小弟菜鸟!
[解决办法]
根据版规,0分帖全部转移至非技术区!
http://topic.csdn.net/u/20080830/18/189fc510-7842-42c1-8029-cf8f3130f4c3.html