I'm using code blocks with gnu gcc compiler. But when I try to compile a range base for startment it gives many errors. So I think the compiler dosn't support C++0x. So I want to know how to know the compiler version I'm using and how to update it correctly to a C++0x supporting one. I'm using Windows XP.
Asked
Active
Viewed 1.6k times
4
-
1Please provide the error messages and a (small, ideally **self contained**) code example VERBATIM. Run `gcc --version` for version info. – Jens Oct 10 '12 at 15:28
-
code `#include
using namespace std; int main()` { int x[20]; for(int &i:x) i=0; }` errors In function 'int main()':| error: expected initializer before ':' token| error: expected primary-expression before '}' token| error: expected ';' before '}' token| error: expected primary-expression before '}' token| error: expected ')' before '}' token| error: expected primary-expression before '}' token| error: expected ';' before '}' token| warning: unused variable 'x'| ||=== Build finished: 7 errors, 1 warnings ===| – lakshitha Oct 10 '12 at 15:38 -
when i gave the command in command prompt `gcc --version` it says gcc was not recognized as a internal or external command @Jens – lakshitha Oct 10 '12 at 15:43
-
1This is really a Code::Blocks question, nothing to do with C++ or gcc. That said: see http://superuser.com/questions/206157/checking-version-of-gcc-compiler-in-codeblocks – Bakkot Oct 10 '12 at 17:41
-
@lakshitha you can edit your question to include the code and errors so it is more readable. – David Brown Oct 10 '12 at 18:20
-
There must be something like C:\Program Files\CodeBlocks and mingw distribution inside of it, in its \bin directory must reside gcc.exe binary. `cd` there in cmd.exe and run `gcc --version`. If version is newer than 4.5, use `g++` with option `-std=c++0x` (like this: `g++ file.cpp -o file.exe -std=c++0x` – Dmytro Sirenko Oct 10 '12 at 18:21
1 Answers
0
This algorithm may help to start with programming with C++11 on Windows:
1) Go to http://mingw.com and download the latest MinGW distribution, install it
2) Download the CodeBlocks installer, install it. During installation it should detect GCC installation and propose to use it as default compiler, accept this.
3) Start a new CodeBlocks project, go to Project -> Properties -> Build options -> Compiler settings -> Compiler flags, then set flag "Have g++ follow the coming C++0x ISO C++ language standard"
4) Compile your first C++11 project and have fun!
By the way, the latest MinGW g++ is of version 4.6.1 as for now, so it has to support most of C++11 features.

Dmytro Sirenko
- 5,003
- 21
- 26
-
thanks EarlGray... this answer did all what i wanted. great answer.. thanks a lot. first i did the first 2 steps and didnt do the 3rd one. then a compiller errar`error: range-based 'for' loops are not allowed in C++98 mode` then i did the step 3 also, now all are correct. thanks again and again. – lakshitha Oct 10 '12 at 19:10
-
1Here is MinGW "distro" with GCC 4.7.2, with newest boost and more. Installation is very easy and works perfect for me. http://nuwen.net/mingw.html – pidabrow Oct 10 '12 at 19:20
-
@piotr_dabrowski It's great, glad to hear GCC 4.7.2 is available. – Dmytro Sirenko Oct 10 '12 at 19:26