C++练习3:输入输出流,文件流,异常处理

#include <iostream> 
 
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
int main(void)
{
vector<string> coll;
vector<string>::iterator pos;
cout<<"Pls input string:"<<endl;
fstream fout("/home/C++/input_file",
fstream::trunc|fstream::in|fstream::out);
if (!fout){
cout << "File open error!\n";
return 0;
}
copy(istream_iterator<string>(cin),
istream_iterator <string>(),
back_inserter(coll));

for(pos=coll.begin(); pos!=coll.end(); ++pos)
{
//cout<<*pos<<" ";
transform(pos->begin(), pos->end(),pos->begin(), ::toupper);
}

copy(coll.begin(), coll.end(), ostream_iterator<string>(fout," "));
//也可将输入流直接重定向到文件
//copy(istream_iterator<string>(cin), ostream_iterator<string>(), ostream_iterator<string>(fout,"")cout<<endl;
fout.close();
}


你可能感兴趣的:(C++练习3:输入输出流,文件流,异常处理)