练习3.14:编写一段程序,用cin输入一组整数并把它们存入一个vector对象。
练习3.15:改写上题的程序,不过这次读入的是字符串。
答案:见云盘程序
练习3.14
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int v1;
vector<int> vec1;
while (cin >> v1){
vec1.push_back(v1);
}
return 0;
}
练习3.15
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string word;
vector<string> text;
while (cin >> word){
text.push_back(word);
}
for (auto &i : text)
cout << i << " " ;
cout << endl;
return 0;
}