請問下列代碼錯在哪裡?
#include<iostream>
#include<vector>
#include<string>
using std::vector;
using namespace std;
int main()
{
int word;
vector<int> var;
vector<int> res_var;
cout << "Please enter a group numbers:" << endl;
while (cin >> word){
var.push_back(word);
for (vector<int>::size_type i = 0; i != (var.size()-1); i = i + 2){
res_var = var[i] + var[i+1];
cout << res_var << " ; " ;
}
if (var.size() % 2 = 1)
cout << "The last one no add." << endl;
}
return 0;
}
錯誤信息:
[Error] no match for 'operator=' (operand types are 'std::vector<int>' and 'int')
[Error] no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::vector<int>')
創建vector的時候初始化大小,res_var後面加下標,最後的if裡寫“==”。