The code below uses std::map::at which was introduced in c++11, however, while specifying an older version (I've tried -std=c++03, -std=c++0x and -std=c++98) in g++ and cmake, it still gets compiled. Other c++11 features do not work, such as range-based for loop.
#include <iostream>
#include <map>
int main() {
std::map<int, int> my_map;
my_map[0] = 1;
std::cout << my_map.at(0);
return 0;
}
g++ command:
g++ -std=c++03 -o main *.cpp
CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project(test)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
add_executable(main main.cpp)
Output in both cases:
1
What could be the issue here? Thanks in advance.