5

This was a code I wrote to see how auto keyword works but it didn't got compiled in Dev C++ and gave the following warning: [Warning] C++11 auto only available with -std=c++11 or -std=gnu++11 How to overcome this glitch and do what the warning tells to do?

#include<iostream>
#include<string>
#include<vector>

using namespace std;
int main()
{
    std::vector<auto> v={2,-1,4,6,7};
    auto beg = v.begin();
    while (beg != v.end())
    {
        ++beg;
        cout<<beg;
    }
}
Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
Mukul Anand
  • 73
  • 1
  • 6
  • Do what the warning tells you to do - add the `-std=c++11` compilation flag – UnholySheep Jul 29 '17 at 08:48
  • Can you please tell me how to do that? – Mukul Anand Jul 29 '17 at 08:52
  • Not so related, but are you forced to use Dev-C++? or you're using it just because it's a lightweight IDE (I remember 10MB-ish, compiler included). I last use it in 2009, and even then, it was considered an old and extremely outdated IDE (shipped with gcc version 3.x or older) – Jim Raynor Jul 29 '17 at 08:58
  • Can you please tell me the best alternative for Dev C++? What do you use currently? @JimRaynor – Mukul Anand Jul 29 '17 at 09:09
  • Code::Blocks is a good choice if you still prefer something lightweight. You can use CB it with the embedded compiler or download the latest gcc version tdm-gcc and tell the IDE to use that compiler. Or Visual Studio Code from Microsoft is now my favorite IDE (cross platform & free). Dev C++ is really buggy. – Jim Raynor Jul 29 '17 at 12:43
  • Compiler apart, you shouldn't use `auto` as the type of the vector, use `std::vector v={2,-1,4,6,7};` instead. Then, being `beg` an iterator, you should dereference it when printing: `std::cout << *beg << ' ';`. – Bob__ Jul 30 '17 at 21:56

1 Answers1

7

You need to enable c++11 in the compiler using the switch instructions can be found here: How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?

Treebeard
  • 322
  • 1
  • 9