Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » make cdt understand 'for (int i : intVector)'(ragne iterator c++11 syntax)
make cdt understand 'for (int i : intVector)' [message #775039] Thu, 05 January 2012 07:21 Go to next message
Asmund Ostvold is currently offline Asmund OstvoldFriend
Messages: 3
Registered: January 2012
Junior Member
What do I need to set to make eclipse/cdt understand the for loop syntax below:

std::vector<int> intVector = {1,2,3,4};
for (int i : intVector) {
      printf("%d\n",i);
}


At the moment I get a yellow undelinging from 'for' to the ending '}'. "Syntax error" it what eclipse tells me.

Regards
Asmund
Re: make cdt understand 'for (int i : intVector)' [message #775189 is a reply to message #775039] Thu, 05 January 2012 14:31 Go to previous messageGo to next message
Marc Khouzam is currently offline Marc KhouzamFriend
Messages: 357
Registered: July 2009
Senior Member
Does this compile with gcc/g++ command-line?

You for loop looks like a java syntax, not C/C++

Marc
Re: make cdt understand 'for (int i : intVector)' [message #775329 is a reply to message #775189] Thu, 05 January 2012 19:31 Go to previous messageGo to next message
Asmund Ostvold is currently offline Asmund OstvoldFriend
Messages: 3
Registered: January 2012
Junior Member
This is C++11.

search for C++11 on wikipedia.org. (I was not allowed include a link)

On the page search for "Range-based for-loop".

To compile with g++:

g++ -std=c++0x

Asmund
Re: make cdt understand 'for (int i : intVector)' [message #775335 is a reply to message #775329] Thu, 05 January 2012 19:46 Go to previous messageGo to next message
Marc Khouzam is currently offline Marc KhouzamFriend
Messages: 357
Registered: July 2009
Senior Member
Oh. I'm not familiar with the current support fo C++11 in CDT. Hopefully someone else can answer. Sorry.
Re: make cdt understand 'for (int i : intVector)' [message #775361 is a reply to message #775335] Thu, 05 January 2012 20:57 Go to previous messageGo to next message
Klaus km is currently offline Klaus kmFriend
Messages: 142
Registered: November 2011
Senior Member
Asmund, add a comment to this bug list or create a new bug entry...?

https://bugs.eclipse.org/bugs/show_bug.cgi?id=327297


Re: make cdt understand 'for (int i : intVector)' [message #775700 is a reply to message #775361] Fri, 06 January 2012 14:42 Go to previous message
Asmund Ostvold is currently offline Asmund OstvoldFriend
Messages: 3
Registered: January 2012
Junior Member
The bug report had a link to bug "Range-based for (bug 327223)". Fix was included in CDT 8.0 and I was running 7.0. Thank you!

I upgraded to Eclipse Indigo and have no problems now.

You will get a beer if we meet!

Asmund

Previous Topic:Advice for large workspaces, multiple projects, third-party libs, executables, etc
Next Topic:Properties -> C/C++ General -> Export Settings (purpose)
Goto Forum:
  


Current Time: Thu Apr 25 18:53:07 GMT 2024

Powered by FUDForum. Page generated in 0.03598 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top