I've downloaded binaries for GCC 4.6, I've set up toolchain executables in co开发者_如何学Pythonde::blocks and yet this fails to compile (I can compile it from the command line though):
int main()
{
int array[5] = { 1, 2, 3, 4, 5 };
for (int& x : array)
x *= 2;
return 0;
}
What shall I do in order to properly configure compiler in code::blocks?
you have to tell g++ that it should compile with c++0x syntax:
g++ --std=c++0x prog.cpp -o prog.x
because this is new C++0x ranged-for syntax:
for (int& x : array)
if this doesn't work, confirm that you use GCC 4.6+
towi@havaloc:~$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
because 4.4 is not enough.
精彩评论