1
#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> vect1(10);
    int value = 5;
    fill(vect1.begin(), vect1.end(), value);
    for (int x : vect1)
        cout << x << " ";
}

this does not compile in dev c++ and shows error.. i directly copied this code from gfg--> link is https://www.geeksforgeeks.org/initialize-a-vector-in-cpp-different-ways/.

EDIT : it says range based for loops are not allowed in cpp98 version

im new to cpp any help is appreciated!

2 Answers2

1

Probably, Dev C++ has C++98 as default, and range-based for loop is from C++11 and onwards.

You click on Tools: enter image description here

Click on Compile Options: enter image description here

Click on Settings: enter image description here

Click on Code Generation: enter image description here On language standards, choose "ISO C++11" enter image description here

But you shouldn't use Dev C++ anymore.

-1

The problem is not the compiler. The #include <bits/stdc++.h> is a standard header which most of the sites use in their example codes and it includes a lot of other c++ header files but this is not defined in any C++ standard and not recommended at all because all compilers doesn't support it and it effects the portability of the code.

Here is the detailed explanation of this: Why should I not #include <bits/stdc++.h>?

Abdul ahad
  • 1,383
  • 7
  • 18