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

【C++学习】vector的使用,输入一串数字,输出相邻和---ShinePans

2014-02-04 14:25 330 查看
/*
*连续使用cin输入,输入进vector,输入一串数字,输出相邻和
*/
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using std::vector;
using std::string;
using namespace std;
int main()
{
int ivec_temp, temp;      //////////定义矢量的临时对象量
vector<int> ints;       //////////定义string 类型的矢量
cout << "Input sentences,I will change it to UPPER!" << endl;
while (cin >> ivec_temp)    /////////输入定量的字符串
ints.push_back(ivec_temp);   ////////////注入ivec矢量
/////////////遍历vector/////////////////////////////////////////
for (int index = 0; index < (ints.size())-1; index++)
{
temp = ints[index] + ints[index + 1];
cout << temp;

}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++