#ifndef _USE_IO_UTILS_ #define _USE_IO_UTILS_ #include <string> #include <vector> #include <iostream> using namespace std; class IOUtils{ public: template <typename T> static void inputMulti(string outstring,vector<T> &values){ T value; cout << outstring << ":"; while(cin >> value){ values.push_back(value); if(LINE==cin.get())break; } } template <typename T> static void input(string outstring,T &value){ cout << outstring << ":" ; cin >> value ; } }; #endif //_USE_IO_UTILS_ 调用测试 #include "IOUtil.h" int main() { vector<string> values; IOUtil::inputMulti("Input", values); vector<string>::iterator p; for (p = values.begin(); p != values.end(); p++) { cout << *p << " "; } cout << endl; return 0; } 输入apple orange banana, 字符串就可以分别存放在vector里面。