您的位置:首页 > 编程语言 > C语言/C++

C++Primer第五版 3.3.2节练习

2015-09-11 09:33 399 查看
练习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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: