How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?
Go to Tools -> Compiler Options -> "Compiler" tab
Check the checkbox labeled, "Add the following commands when calling the compiler"
And add in the text entry box, "-std=c++11" or if that doesn't work "-std=C++0x"
Should be something like that anyway, I haven't had Dev C++ installed for many years, so I had to look at some screenshots on Google to remember.
I am using the dev c++ and i am getting the error ( C++98 'array' must be initialized by constructor)
You are trying to use the so called initializer_list
(take a look here if you do not know what they are) which is a way of costructing objects introduced by c++11
.
Hence you need to tell your compiler that you want to use c++11
by passing the argument -std=c++11
to the compiler itself.
Take a look at this question to see how to do it.
Format specifier %Lf is giving errors for `long double` variables
Your compiler doesn't recognize %Lf
, you need to provide the compiler flag -D__USE_MINGW_ANSI_STDIO=1
Example:
$ gcc filename.c -Wall -Wextra -pedantic -O3 -D__USE_MINGW_ANSI_STDIO=1
^^^^^^^^^^^^^^^^^^^^^^^^^^
As you are using Dev-C++
, you should probably also add -std=c11
flag to enable C11 standard.
This thread explains how you should add flags to Dev-C++
:
How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?
So you need to add the flags -std=c11
and -D__USE_MINGW_ANSI_STDIO=1
using the instructions in the linked thread.
Since Dev-C++ uses an older standard, it's possible that adding only -std=c11
can solve the issue. Try it first.
Dev C++ not detecting error about using only single angle bracket with cout?
The compiler is taking advantage of ostream
's operator bool
. Before C++ 11, it was implemented as operator void *
and returned a void*
rather than bool
resulting in a syntactically legal (but logically incorrect) pointer < pointer comparison. You've found one of many good reasons the operator was replaced with the modern bool
version.
The suggestions of the commenters below the question of don't use such an ancient compiler hold, but depending on the age of your Dev-C++ install, the simplest solution may be to turn on C++11 support. If your copy of Dev-C++ is too old for that, and you still want to use it, I join drescherjm in recommending you replace the compiler it came with with an up-to-date compiler from msys2. Here are good instructions on installing msys2 and its GCC.
If you want to keep using Dev C++ but don't care about the version, here's a link to the most up-to-date version that I'm aware of. It comes bundled with GCC 9.3, which is only a year old at the time of writing and supports C++17.
How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?
Go to Tools -> Compiler Options -> "Compiler" tab
Check the checkbox labeled, "Add the following commands when calling the compiler"
And add in the text entry box, "-std=c++11" or if that doesn't work "-std=C++0x"
Should be something like that anyway, I haven't had Dev C++ installed for many years, so I had to look at some screenshots on Google to remember.
Can't compile C++ file.cpp. C++98 mode
As mentioned in the previous answer, you are attempting to use a feature of the latest C++ standard (called C++11) while compiling for older standard.
C++11 is the latest C++ standard and the only one supporting range based for.
Now you need to distinguish between the C++ standard and the compiler support for that standard.
Along the past few years, support for C++11 features was gradually added to the gcc compiler.
The following link shows which C++11 feature is supported by which gcc version:
C++0x/C++11 Support in GCC
As you can see, range based for was added in gcc 4.6, so you do not need gcc 4.8 in order to use this feature - gcc 4.6 or later will suffice.
When compiling, you will also need to tell the compiler which standard to compile against. The -std=whatever tells the compiler which standard to use.
You are currently using "-std=c99", telling the compiler to compile using an old C++ standard. Instead you need to set this flag to c++11. If this doesn't work on the gcc version you are using, try using "-std=c++0x" instead (C++0x is an old name of the C++11 standard.)
Related Topics
How to Use the Qt'S Pimpl Idiom
Is the Safe-Bool Idiom Obsolete in C++11
C++ Virtual Function Return Type
What's "Wrong" With C++ Wchar_T and Wstrings? What Are Some Alternatives to Wide Characters
How to Change Mode from C++98 Mode in Dev-C++ to a Mode That Supports C++0X (Range Based For)
How to Efficiently Perform Double/Int64 Conversions With Sse/Avx
How to Find Which Elements Are in the Bag, Using Knapsack Algorithm [And Not Only the Bag'S Value]
What Exactly Is a Reentrant Function
Check If a String Contains a String in C++
Difference Between String and Char[] Types in C++
Difference Between Angle Bracket ≪ ≫ and Double Quotes " " While Including Header Files in C++
Is There Any Overhead to Declaring a Variable Within a Loop - C++