I am trying to learn STL (vectors, maps, sets) using Dev C++. But it is giving me error. Please look at the given code and error.
#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;
}
Error:
9 33 G:\C++\STL.cpp [Error] in C++98 'A' must be initialized by constructor, not by '{...}'
9 33 G:\C++\STL.cpp [Error] could not convert '{11, 84, 1, 57}' from '' to 'std::vector'
This is the error that it is throwing. When I am using same code in online IDE then it is running properly.