I am trying to run this program:
#include <vector>
#include<iostream>
#include<numeric>
#include<algorithm>
using namespace std;
int main()
{
std::vector<int> V(10);
// Use std::iota to create a sequence of integers 0, 1, ...
std::iota(V.begin(), V.end(), 1);
// Print the unsorted data using std::for_each and a lambda
std::cout << "Original data" << std::endl;
std::for_each(V.begin(), V.end(), [](auto i) { std::cout << i << " "; });
std::cout << std::endl;
// Sort the data using std::sort and a lambda
std::sort(V.begin(), V.end(), [](auto i, auto j) { return (i > j); });
// Print the sorted data using std::for_each and a lambda
std::cout << "Sorted data" << std::endl;
std::for_each(V.begin(), V.end(), [](auto i) { std::cout << i << " "; });
std::cout << std::endl;
return 0;
}
But it gives me the error
main.cpp:18: error: parameter declared 'auto'
std::for_each(V.begin(), V.end(), [](auto i) { std::cout << i << " "; });
^
Now I am pretty sure this is due to my compiler not using c++14
I'm using QT5.5.1, GCC g++ 4.8.4 compiler
I added this in the .pro file:
CONFIG += c++14
But that didn't change anything..
My .pro file is now like this:
TEMPLATE = app
CONFIG += c++14
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
I tried updating my compiler to g++ 5 but that didn't seem to work?