1

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?

aze45sq6d
  • 876
  • 3
  • 11
  • 26
  • Did you upgrade the compile or install a new version in a different directory? If it is in a different directory you are going to have to point Qt to the new instance of g++. Also see: https://gcc.gnu.org/projects/cxx1y.html – NathanOliver Jan 11 '16 at 13:29
  • Hi, the linked question should contain all the required information for you (and also happens to be the first internet-search result for me). Best Regards – Sebastian Mach Jan 11 '16 at 13:31
  • Hey phresnel, That's the question I looked at before posting this, However I added the CONFIG+= c++14 etc like they did in there. It was mentioned that since QT5.4 we can add CONFIG += c++14 to the pro file – aze45sq6d Jan 11 '16 at 13:33

0 Answers0