【C++學習】vector的使用,輸入一串數字,輸出相鄰和---ShinePans
阿新 • • 發佈:2019-02-16
/* *連續使用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; }