Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

g++ mode for c++ 11

91 views
Skip to first unread message

bilsch

unread,
Mar 3, 2015, 6:21:38 AM3/3/15
to
I'm using g++ on Ubuntu 14.04. I found a site that has a huge reference
for c++ and c commands. The command descriptions include sample
demonstration programs. This will be a valuable resource because I don't
know c++ - I am a C programmer. I need to learn some C++. So I tried to
compile one of the demonstration programs (listed below) but I got the
following error from g++ that comes with Ubuntu:

error: range-based ‘for’ loops are not allowed in C++98 mode

I think the site is current with c++ 11. It looks like g++ is current
with C++98. How do I get g++ current with C++ 11?

#include <iostream>

#include <cstring>


int main()

{
const char* src = "hi";

char dest[6] = {'a', 'b', 'c', 'd', 'e', 'f'};;

std::strncpy(dest, src, 5);


std::cout << "The contents of dest are: ";

for (char c : dest) {

if (c) {

std::cout << c << ' ';

} else {

std::cout << "\\0" << ' ';

}

}

std::cout << '\n';

}

Wouter van Ooijen

unread,
Mar 3, 2015, 6:27:48 AM3/3/15
to
bilsch schreef op 03-Mar-15 om 12:20 PM:
> I'm using g++ on Ubuntu 14.04. I found a site that has a huge reference
> for c++ and c commands. The command descriptions include sample
> demonstration programs. This will be a valuable resource because I don't
> know c++ - I am a C programmer. I need to learn some C++. So I tried to
> compile one of the demonstration programs (listed below) but I got the
> following error from g++ that comes with Ubuntu:
>
> error: range-based ‘for’ loops are not allowed in C++98 mode
>
> I think the site is current with c++ 11. It looks like g++ is current
> with C++98. How do I get g++ current with C++ 11?


-std=c++11

Wouter

bilsch

unread,
Mar 3, 2015, 6:41:10 AM3/3/15
to

> -std=c++11
>
> Wouter

Thank you. Bill S.

Scott Lurndal

unread,
Mar 3, 2015, 9:15:33 AM3/3/15
to
bilsch <kin...@comcast.net> writes:
>I'm using g++ on Ubuntu 14.04. I found a site that has a huge reference
>for c++ and c commands. The command descriptions include sample
>demonstration programs. This will be a valuable resource because I don't
>know c++ - I am a C programmer. I need to learn some C++. So I tried to
>compile one of the demonstration programs (listed below) but I got the
>following error from g++ that comes with Ubuntu:
>
> error: range-based ‘for’ loops are not allowed in C++98 mode

man pages are your friend:

bash$ man g++ | col -b | grep -i c++11

...
GNU dialect of -std=c++11. Support for C++11 is still

see the description of the -std parameter.


Jorgen Grahn

unread,
Mar 7, 2015, 2:44:54 PM3/7/15
to
On Tue, 2015-03-03, Scott Lurndal wrote:
> bilsch <kin...@comcast.net> writes:
...
>>compile one of the demonstration programs (listed below) but I got the
>>following error from g++ that comes with Ubuntu:
>>
>> error: range-based ???for??? loops are not allowed in C++98 mode
>
> man pages are your friend:
>
> bash$ man g++ | col -b | grep -i c++11

Yes, but with GCC you really need the info pages. Not my favorite
documentation format, but that's where the full compiler documentation
is, so you need to have it and be able to navigate it.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

David Brown

unread,
Mar 8, 2015, 3:57:10 PM3/8/15
to
On 07/03/15 20:44, Jorgen Grahn wrote:
> On Tue, 2015-03-03, Scott Lurndal wrote:
>> bilsch <kin...@comcast.net> writes:
> ...
>>> compile one of the demonstration programs (listed below) but I got the
>>> following error from g++ that comes with Ubuntu:
>>>
>>> error: range-based ???for??? loops are not allowed in C++98 mode
>>
>> man pages are your friend:
>>
>> bash$ man g++ | col -b | grep -i c++11
>
> Yes, but with GCC you really need the info pages. Not my favorite
> documentation format, but that's where the full compiler documentation
> is, so you need to have it and be able to navigate it.
>
> /Jorgen
>

I have never found "info" pages to be any use. The gcc manuals are fine:

<https://gcc.gnu.org/onlinedocs/>

Use the online html, html tarballs, or pdf files according to preference.

gcc also comes with a fairly good built in help (with "--help -v" as a
starting point) - recent versions let you get details of different
groups of command-line switches.

Jorgen Grahn

unread,
Mar 10, 2015, 1:39:58 PM3/10/15
to
On Sun, 2015-03-08, David Brown wrote:
> On 07/03/15 20:44, Jorgen Grahn wrote:
>> On Tue, 2015-03-03, Scott Lurndal wrote:
>>> bilsch <kin...@comcast.net> writes:
>> ...
>>>> compile one of the demonstration programs (listed below) but I got the
>>>> following error from g++ that comes with Ubuntu:
>>>>
>>>> error: range-based ???for??? loops are not allowed in C++98 mode
>>>
>>> man pages are your friend:
>>>
>>> bash$ man g++ | col -b | grep -i c++11
>>
>> Yes, but with GCC you really need the info pages. Not my favorite
>> documentation format, but that's where the full compiler documentation
>> is, so you need to have it and be able to navigate it.

> I have never found "info" pages to be any use. The gcc manuals are fine:
>
> <https://gcc.gnu.org/onlinedocs/>

Aren't those the same thing as the info pages, though?

> Use the online html, html tarballs, or pdf files according to preference.

It's an individual preference. I hate info, but at least I can use it
within Emacs which I'm using /anyway/ ... and the HTML stuff inherits
some of the bad aspects of the info documentation so you suffer from
it, to some degree, in either case.

And the main point was "there's important documentation for GCC which
isn't in the man pages".

> gcc also comes with a fairly good built in help (with "--help -v" as a
> starting point) - recent versions let you get details of different
> groups of command-line switches.

Never tried it. But I should add that I looked at the man page now,
and it was better than I remembered it -- at least command-line
options and environment variables were properly documented, not just
listed with no explanation like I remembered them.

David Brown

unread,
Mar 10, 2015, 5:21:57 PM3/10/15
to
On 10/03/15 18:39, Jorgen Grahn wrote:
> On Sun, 2015-03-08, David Brown wrote:
>> On 07/03/15 20:44, Jorgen Grahn wrote:
>>> On Tue, 2015-03-03, Scott Lurndal wrote:
>>>> bilsch <kin...@comcast.net> writes:
>>> ...
>>>>> compile one of the demonstration programs (listed below) but I got the
>>>>> following error from g++ that comes with Ubuntu:
>>>>>
>>>>> error: range-based ???for??? loops are not allowed in C++98 mode
>>>>
>>>> man pages are your friend:
>>>>
>>>> bash$ man g++ | col -b | grep -i c++11
>>>
>>> Yes, but with GCC you really need the info pages. Not my favorite
>>> documentation format, but that's where the full compiler documentation
>>> is, so you need to have it and be able to navigate it.
>
>> I have never found "info" pages to be any use. The gcc manuals are fine:
>>
>> <https://gcc.gnu.org/onlinedocs/>
>
> Aren't those the same thing as the info pages, though?

It is quite possible that they are the same - I don't find info pages
useful because the format is terrible and navigation is difficult, not
because the information contained is bad. HTML format is great for
jumping around, and for having multiple tabs with different parts of the
documentation open at once. PDF format is great when you want to read
through documentation like a book, search the whole thing, or print out
pages. I therefore have not bothered looking at the gcc info pages.

>
>> Use the online html, html tarballs, or pdf files according to preference.
>
> It's an individual preference. I hate info, but at least I can use it
> within Emacs which I'm using /anyway/ ... and the HTML stuff inherits
> some of the bad aspects of the info documentation so you suffer from
> it, to some degree, in either case.

Indeed it is a matter of personal preference - I guess /some/ people
must like info!

However, /you/ were the one who said you didn't like info, but felt you
had to use it to get the information you needed - I was just trying to
be helpful by recommending alternative formats with (apparently) the
same information.

>
> And the main point was "there's important documentation for GCC which
> isn't in the man pages".
>
>> gcc also comes with a fairly good built in help (with "--help -v" as a
>> starting point) - recent versions let you get details of different
>> groups of command-line switches.
>
> Never tried it. But I should add that I looked at the man page now,
> and it was better than I remembered it -- at least command-line
> options and environment variables were properly documented, not just
> listed with no explanation like I remembered them.
>

The man pages and the built-in help have all got very much better in
recent versions of gcc.


Jorgen Grahn

unread,
Mar 10, 2015, 6:02:41 PM3/10/15
to
On Tue, 2015-03-10, David Brown wrote:
> On 10/03/15 18:39, Jorgen Grahn wrote:
>> On Sun, 2015-03-08, David Brown wrote:
...

>>> Use the online html, html tarballs, or pdf files according to preference.
>>
>> It's an individual preference. I hate info, but at least I can use it
>> within Emacs which I'm using /anyway/ ... and the HTML stuff inherits
>> some of the bad aspects of the info documentation so you suffer from
>> it, to some degree, in either case.
>
> Indeed it is a matter of personal preference - I guess /some/ people
> must like info!

At least Stallman himself.

> However, /you/ were the one who said you didn't like info, but felt you
> had to use it to get the information you needed - I was just trying to
> be helpful by recommending alternative formats with (apparently) the
> same information.

Yes, and I kind of understood that.
0 new messages