Open In App

How to fix auto keyword error in Dev-C++

Improve
Improve
Like Article
Like
Save
Share
Report

The auto keyword in C++ specifies that the type of the variable that is being declared will be automatically deducted from its initializer. In case of functions, if their return type is auto then that will be evaluated by return type expression at runtime.




// C++ program to illustrate the auto
// keyword in DevC++ compiler
#include <bits/stdc++.h>
using namespace std;
  
// Driver Code
int main()
{
    // Initialize vector
    vector<int> v = { 1, 2, 3, 4, 5 };
  
    // Traverse vector using auto
    for (auto x : v) {
  
        // Print elements of vector
        cout << x << " ";
    }
}


Output:

1 2 3 4 5

The same code produces error in Dev-C++:

If you want to traverse a vector using an auto keyword (as shown in the above code), then it will show error as:

Why does this error occur in Dev-C++:

The auto keyword introduces in C++ 11, and it is allowed to the user to leave the type deduction to the compiler itself. But while running a program in Dev-C++ then it will be showing error, because in Dev-C++ inbuilt C++98 compiler so that’s by that error occurs.

How to fix this error:

Below are the steps to solve the error:

  1. Open Dev C++ go to ->tools.
  2. Click on ->compiler options(1st option).
  3. A new window will open and in that window click on -> settings:
  4. Go to -> code generation:
  5. In language standard column(std) choose ->ISO C++11:
  6. Click on OK and After that the code will execute and will give no error.

Now the code works fine and prints the expected output.


Last Updated : 15 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads