关于C++ vector 的问题

请问下列代码错在哪里?
#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>')
查看全部
baozhadehulu
baozhadehulu
2015/06/03 14:27
  • c++
  • vector
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

7个回复