Author Topic: I need help setting up C::B 10.05 for C++0x...  (Read 4978 times)

Offline tabl3six

  • Single posting newcomer
  • *
  • Posts: 5
I need help setting up C::B 10.05 for C++0x...
« on: August 06, 2011, 04:42:52 am »
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

  • Guest
Re: I need help setting up C::B 10.05 for C++0x...
« Reply #1 on: August 06, 2011, 08:56:02 am »
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.

Offline tabl3six

  • Single posting newcomer
  • *
  • Posts: 5
Re: I need help setting up C::B 10.05 for C++0x...
« Reply #2 on: August 07, 2011, 07:19:53 pm »
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;
}

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.







« Last Edit: August 07, 2011, 08:10:22 pm by tabl3six »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7607
    • My Best Post
Re: I need help setting up C::B 10.05 for C++0x...
« Reply #3 on: August 07, 2011, 08:53:06 pm »
These are Compiler problems NOT Code::Blocks problems expect this thread to be closed for violation of the forum rules.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

zabzonk

  • Guest
Re: I need help setting up C::B 10.05 for C++0x...
« Reply #4 on: August 07, 2011, 09:20:55 pm »
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.
« Last Edit: August 07, 2011, 09:27:29 pm by Neil Butterworth »

Offline tabl3six

  • Single posting newcomer
  • *
  • Posts: 5
Re: I need help setting up C::B 10.05 for C++0x...
« Reply #5 on: August 07, 2011, 10:48:33 pm »
Sorry, wasn't sure if it was appropriate to post this question.

Neil:
Yeah, That is why I'm stuck on this. Why would this be in the book if I couldn't use it.
The book is "C++ without fear by Brain Overland"

Do you know it?

zabzonk

  • Guest
Re: I need help setting up C::B 10.05 for C++0x...
« Reply #6 on: August 07, 2011, 11:47:41 pm »
> Do you know it?

Nope. My rules for buying C++ books are quite simple - must be published by Addison Wesley and/or must be written by or recommended by one of the original C++ development team. Most books on programming are complete and utter rubbish, but these simple rules should allow you to avoid the crap, for C++ at least.