Hello,
I'm learning STL and lambdas for the very latest version of C++.
I was hoping that in the following program I would fill a vector with values 1 to 6 and then to print them out. But the compiler complains that for_each is not recognized!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
include <iostream>
#include <algorithm>
#include <vector>
usingnamespace std;
int main()
{
vector<int>my_vector;
for(int i=0; i < 6; i++)
my_vector.push_back(i);
for_each( my_vector.begin(), my_vector.end(), [ ](int n){ std::cout<<n;});
return 0;
}
Ok, that's going to be hard, because I am using either CodeBlocks ot QTCreator. But I must point out that -std=c++11 is "enabled by default" as the above messages indicate
It is not c++11 mode that is enabled by default, but warning.
In C::B setting is under settings→compiler. I do not familiar with QT creator, but any sane IDE should at least allow to add your own compiler parameters.
OK, it turns out that I found after much searching that I could turn on
-std=c++11
and this fixes the problem. But I was misled by the message that
led me to believe this was turned on by default.