8.10
#include <sstream> #include <fstream> #include <iostream> #include <string> #include <vector> using namespace std; void main() { vector <string> ch; string word, line; ifstream input("test.txt"); if (!input) cerr << "cannot open file!"; while (getline(input, line)) ch.push_back(line); input.close(); for (auto s : ch) { istringstream record(s); while (record >> word) cout << word << ‘\n‘; } system("pause"); }
原文:http://1271415.blog.51cto.com/1261415/1584532