C++primer习题3.14 vector<string>读写字符
时间:2011-06-08 来源:hailong
#include <iostream> #include <iomanip> #include <fstream> #include <string> #include <iostream> #include <vector> using namespace std; void get_upper(string &s) { for(size_t i = 0; i != s.size(); ++i) { s[i] = toupper(s[i]); } } int main() { ifstream infile("E:\\test.txt"); if (!infile) { cerr << "error" << endl; } vector<string> svec; string s; while (infile) { infile >> s; svec.push_back(s); } for(size_t i = 0; i != svec.size(); ++i) { get_upper(svec[i]); cout << svec[i] << " "; if ((i+1)%8==0) { cout << endl; } } }
相关阅读 更多 +