[疑惑中]!!关于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