User forums > Help
I need help setting up C::B 10.05 for C++0x...
tabl3six:
I tried setting the compiler flag [-std=c++0x] and that did not work. I posted on another board and was told that the compiler I was using most likely was old and needed the a newer one.
I'm using GNU GCC as the selected compiler. C++ compiler: mingw32-g++.exe
I'm very new to C++ so if you could give some details on what to do to correct the problem. Thanks.
If I'm out of line posting this please ignore.
zabzonk:
Get a more up to date version of GCC - I have a blog about how to do this here http://latedev.wordpress.com/2011/06/20/how-to-install-a-c-compiler-on-windows/
And "did not work" is a phrase that should never, ever be used when posting here - describe exactly what you did, what the symptoms of the problem are, providing compiler output.
tabl3six:
Thank you and I do realize that I wasn't as detailed in my question as I should have been.
Here is what I'm trying to do. I'm new to C++ and going through a book(C++ without fear) trying to get the basics. I'm on a chapter that is an introduction to the new C++0x features. I'm not able to get a range based for command example problem in the book to work.
This is the code which is straight out of the book:
--- Code: ---#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
#define SIZE_OF_ARRAY 5
int main() {
int arr[SIZE_OF_ARRAY];
int total = 0;
// For each element, prompt for a value,
// store, and add to total.
//
for (int& n : arr) {
cout << "Enter array value: ";
cin >> n;
total += n;
}
cout << "Here are the values: ";
// Print each element.
//
for (int n : arr)
cout << n << endl;
cout << "Total is: " << total << endl;
cout << "Now, I'm going to zero out ";
cout << "the values." << endl;
// Set each element to 0.
//
for (int& n : arr)
n = 0;
cout << "Here are the values: ";
for (int n : arr)
cout << n << endl;
system( PAUSE );
return 0;
}
--- End code ---
Here are the build errors
||=== Example 10-2, Debug ===|
||In function 'int main()' : |
|17|error: expected initializer before ':' token|
|26|error: expected primary-expression before 'for'|
|26|error: expected ')' before 'for'|
|26|error: expected initializer before ':' token|
|29|error: expected ')' before ';' token|
|34|error: expected initializer before ':' token|
|38|error: expected primary-expression before 'for'|
|38|error: expected ')' before 'for'|
|38|error: expected initializer before ':' token|
|40|error: 'PAUSE' was not declared in this scope|
|41|error: expected primary-expression before 'return'|
|41|error: expected ')' before 'return'|
|11|warning: unused variable 'arr'|
||=== Build finished: 12 errors, 1 warnings ===|
I did go through the tutorial and was able to get tdm4-5-2 gcc installed and the sample programs to work. One thing I'm confused about is here http://gcc.gnu.org/projects/cxx0x.html they state you need GCC 4.6.
I did try using tdm4-5-2 with command prompt and C::B again same errors.
Not sure what to do now, may skip this chapter, feel like I'm waisting too much time on this.
stahta01:
These are Compiler problems NOT Code::Blocks problems expect this thread to be closed for violation of the forum rules.
Tim S.
zabzonk:
GCC only supports range-based for in 4.6 - see http://gcc.gnu.org/projects/cxx0x.html - the current version of TDM does not support it. If the book really suggests you use C++ features which have not yet been standardised, and which are not supported by commonly used compilers, then it is, frankly, crap.
Navigation
[0] Message Index
[#] Next page
Go to full version