“ A”必须由构造函数而不是“ {...}”

时间:2020-09-17 06:51:03

标签: c++ stl

我正在尝试使用Dev C ++学习STL(向量,地图,集合)。但这给了我错误。请查看给定的代码和错误。

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector <int> A = {11, 84, 1, 57};

    cout << A[2] << endl;

    sort(A.begin(), A.end());  //1, 11, 57, 84

    bool present = binary_search(A.begin(), A.end(), 57);  //true
    present = binary_search(A.begin(), A.end(), 5);  //false

    A.push_back(158);  //1, 11, 57, 84, 158
    A.push_back(158);  //1, 11, 57, 84, 158, 158
    A.push_back(158);  //1, 11, 57, 84, 158, 158, 158
    A.push_back(285);  //1, 11, 57, 84, 158, 158, 158, 285
  
    vector<int>::iterator it = lower_bound(A.begin(), A.end(), 158);   //>=
    vector<int>::iterator it2 = upper_bound(A.begin(), A.end(), 158);  //< (returns 1st element 
    which is strictly greater than 158)
 
    cout << *it << " " << *it2 << endl;  //
    cout << it2 - it <<endl;  //

    //return 0;
}

错误:

9 33 G:\ C ++ \ STL.cpp C ++ 98'A'中的[错误]必须由构造函数而不是'{...}'初始化

9 33 G:\ C ++ \ STL.cpp [错误]无法将'{11,84,1,57}'从''转换为'std :: vector'

这是它引发的错误。当我在在线IDE中使用相同的代码时,它将正常运行。

0 个答案:

没有答案