f



Is this C or C++?

Simple question. If the task is (for example):
"Write a   C++ program which asks user his name (less than 20 chars) and 
prints it."

Then, is this code a correct answer:

char name[100];
cout<<"Your name?"<<endl;
cin>>name;
cout<<name<<endl;

The point being, that the code uses C string "char name[]" and not C++ 
std::string.
C is a subset of C++, so isnt it logically speaking a C++ program? 


0
no6909 (32)
11/19/2013 9:44:40 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

23 Replies
1228 Views

Similar Articles

[PageSpeed] 56

On Tue, 19 Nov 2013 21:44:40 -0000, "crea" <no@com.notvalid> wrote:

>Simple question. If the task is (for example):
>"Write a   C++ program which asks user his name (less than 20 chars) and 
>prints it."
>
>Then, is this code a correct answer:
>
>char name[100];
>cout<<"Your name?"<<endl;
>cin>>name;
>cout<<name<<endl;
>
>The point being, that the code uses C string "char name[]" and not C++ 
>std::string.
>C is a subset of C++, so isnt it logically speaking a C++ program? 

The belief that C is a proper subset of C++ is the source of many
misconceptions.

The fact that cin supports reading into a char array is what makes the
code legal C++.  Whether using a std::string would make it more of a
C++ program is a philosophical discussion.

-- 
Remove del for email
0
schwarzb3978 (1424)
11/19/2013 10:04:54 PM
"Barry Schwarz" <schwarzb@dqel.com> wrote in message 
news:3vnn89l8cb3kr8nj52n9dutjlivpokikha@4ax.com...
> On Tue, 19 Nov 2013 21:44:40 -0000, "crea" <no@com.notvalid> wrote:
>
>>Simple question. If the task is (for example):
>>"Write a   C++ program which asks user his name (less than 20 chars) and
>>prints it."
>>
>>Then, is this code a correct answer:
>>
>>char name[100];
>>cout<<"Your name?"<<endl;
>>cin>>name;
>>cout<<name<<endl;
>>
>>The point being, that the code uses C string "char name[]" and not C++
>>std::string.
>>C is a subset of C++, so isnt it logically speaking a C++ program?
>
> The belief that C is a proper subset of C++ is the source of many
> misconceptions.

Ok, I did not really mean 100% like that, but in this example it does not 
matter if its 100%  or not.

>
> The fact that cin supports reading into a char array is what makes the

> code legal C++.  Whether using a std::string would make it more of a
> C++ program is a philosophical discussion.

Here I think I agree.

But this might be a real "problem" in a school assignments, or in a 
programming job interview, is asked to code something. 


0
no6909 (32)
11/19/2013 10:26:54 PM
On Wednesday, 20 November 2013 00:26:54 UTC+2, crea  wrote:
> "Barry Schwarz" <schwarzb@dqel.com> wrote in message 
> news:3vnn89l8cb3kr8nj52n9dutjlivpokikha@4ax.com...
> > On Tue, 19 Nov 2013 21:44:40 -0000, "crea" <no@com.notvalid> wrote:
> >
> >>Simple question. If the task is (for example):
> >>"Write a   C++ program which asks user his name (less than 20 chars) and
> >>prints it."
> >>
> >>Then, is this code a correct answer:
> >>
> >>char name[100];
> >>cout<<"Your name?"<<endl;
> >>cin>>name;
> >>cout<<name<<endl;

If you meant it as listing of a program then it certainly is not. 
I can tell without trying that it does not compile on any C++
or C compiler I know of. 

> >>The point being, that the code uses C string "char name[]" and not C++
> >>std::string.
> >>C is a subset of C++, so isnt it logically speaking a C++ program?
> >
> > The belief that C is a proper subset of C++ is the source of many
> > misconceptions.
> 
> Ok, I did not really mean 100% like that, but in this example it does not 
> matter if its 100%  or not.

Yes, since it was not valid program.

> > The fact that cin supports reading into a char array is what makes the
> > code legal C++.  Whether using a std::string would make it more of a
> > C++ program is a philosophical discussion.
> 
> Here I think I agree.
> 
> But this might be a real "problem" in a school assignments, or in a 
> programming job interview, is asked to code something.

Schools teach people the art of getting best grades out of
fellow person. That is important skill but persons differ so 
we can not advice here without seeing particular individual.
Same skill matters in work interview as well, but the person
interviewing you is often smarter than the one in school so
be warned. ;)

On any case it has nothing to do with similarities or 
differences between C and C++.

0
ootiib (965)
11/20/2013 5:08:42 PM
On 19.11.2013 22:44, crea wrote:
> Simple question. If the task is (for example):
> "Write a   C++ program which asks user his name (less than 20 chars) and
> prints it."
>
> Then, is this code a correct answer:
>
> char name[100];
> cout<<"Your name?"<<endl;
> cin>>name;
> cout<<name<<endl;
>
> The point being, that the code uses C string "char name[]" and not C++
> std::string.
> C is a subset of C++, so isnt it logically speaking a C++ program?

The code is non-C by using iostreams.

It's not a good answer, on three counts:

* You risk a buffer overrun (storing data beyond the end of the array), 
which is Undefined Behavior.
* A student might type in his or her full name, with a space or two, in 
which case the above, using >>, will read only the first "word".
* After the above code there is at least a newline left in the input 
buffer, which might cause havoc with a subsequent input operation.

To fix the buffer overrun use e.g. std::string. To fix the "word-by-word 
input" problem as well as the problem of leaving text in the input 
buffer, use std::getline instead of >>.

Cheers & hth.,

- Alf


0
usenet30 (890)
11/20/2013 5:15:12 PM
"�� Tiib" <ootiib@hot.ee> wrote in message 
news:b1e33088-ae50-438d-9443-158e72597919@googlegroups.com...
>> But this might be a real "problem" in a school assignments, or in a
>> programming job interview, is asked to code something.
>
> Schools teach people the art of getting best grades out of
> fellow person. That is important skill but persons differ so
> we can not advice here without seeing particular individual.
> Same skill matters in work interview as well, but the person
> interviewing you is often smarter than the one in school so
> be warned. ;)
>
> On any case it has nothing to do with similarities or
> differences between C and C++.

I mean that in C++ job interview they might as to write a C++ code. One 
might use partly C-style library functions, the other pure C++. But 
according to definition they both are actually C++ codes.

Maybe the thing is that if there is a C++ (library) version of certain 
code/function then that should be used instead of C version? So C library 
calls should be avoided always in C++ code (if just possible and there is a 
C++ counter part)? 


0
no6909 (32)
11/21/2013 8:22:17 AM
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> wrote in message 
news:l6iqn2$jf3$1@dont-email.me...
> On 19.11.2013 22:44, crea wrote:
>> Simple question. If the task is (for example):
>> "Write a   C++ program which asks user his name (less than 20 chars) and
>> prints it."
>>
>> Then, is this code a correct answer:
>>
>> char name[100];
>> cout<<"Your name?"<<endl;
>> cin>>name;
>> cout<<name<<endl;
>>
>> The point being, that the code uses C string "char name[]" and not C++
>> std::string.
>> C is a subset of C++, so isnt it logically speaking a C++ program?
>
> The code is non-C by using iostreams.
>
> It's not a good answer, on three counts:
>
> * You risk a buffer overrun (storing data beyond the end of the array), 
> which is Undefined Behavior.
> * A student might type in his or her full name, with a space or two, in 
> which case the above, using >>, will read only the first "word".
> * After the above code there is at least a newline left in the input 
> buffer, which might cause havoc with a subsequent input operation.
>
> To fix the buffer overrun use e.g. std::string. To fix the "word-by-word 
> input" problem as well as the problem of leaving text in the input buffer, 
> use std::getline instead of >>.

ok, true I was careless in making the C program. Here is the working 
version:
**************
#include <stdio.h>

int main()
{
  int bytes_read;
  int nbytes = 100;
  char *my_string;

  puts ("Please enter a line of text.");

  /* These 2 lines are the heart of the program. */
  my_string = (char *) malloc (nbytes + 1);
  bytes_read = getline (&my_string, &nbytes, stdin);

  if (bytes_read == -1)
    {
      puts ("ERROR!");
    }
  else
    {
      puts ("You typed:");
      puts (my_string);
    }

  return 0;
}*************

Now, this has no issues what you said if max name lenght is limited to, say, 
30 or 99..


0
no6909 (32)
11/21/2013 8:32:19 AM
crea <no@com.notvalid> wrote:
> int main()

I'm not very versed in C99, but at least in the older C you had to write
that as "int main(void)". (Has this changed in C99?)

>  bytes_read = getline (&my_string, &nbytes, stdin);

I don't think that's standard C. getline() is a POSIX extension.

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
0
nospam270 (2948)
11/21/2013 10:03:00 AM
"Juha Nieminen" <nospam@thanks.invalid> wrote in message 
news:l6kloj$1j0s$1@adenine.netfront.net...
> crea <no@com.notvalid> wrote:
>> int main()
>
> I'm not very versed in C99, but at least in the older C you had to write
> that as "int main(void)". (Has this changed in C99?)

hmm, I never used that. Even when coding in 90 s, like VC++ 6

>
>>  bytes_read = getline (&my_string, &nbytes, stdin);
>
> I don't think that's standard C. getline() is a POSIX extension.

This is not a point though in this debate as C++  and C can be mixed as the 
question was that can I mix C with C++ and still call it C++ program. 


0
no6909 (32)
11/21/2013 10:15:28 AM
On 21.11.2013 11:15, crea wrote:
>
> This is not a point though in this debate as C++  and C can be mixed as the
> question was that can I mix C with C++ and still call it C++ program.

Yes of course you can: you can't /not/ do that.

Consider that `int` comes from C, just to take one very obvious example. 
So you can't even express the required C++ `main` function without some 
bits of C sneaking in. Including the non-const'ness of the arguments of 
that function, if you declare the arguments.

But whether you can get away with mostly C on an interview or exam, when 
the task is to code up a C++ program, well that's another matter entirely...


Cheers & hth.,

- Alf

0
usenet30 (890)
11/21/2013 10:31:46 AM
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> wrote in message 
news:l6knej$3ki$1@dont-email.me...
> On 21.11.2013 11:15, crea wrote:
>>
>> This is not a point though in this debate as C++  and C can be mixed as 
>> the
>> question was that can I mix C with C++ and still call it C++ program.
>
> Yes of course you can: you can't /not/ do that.
>
> Consider that `int` comes from C, just to take one very obvious example. 
> So you can't even express the required C++ `main` function without some 
> bits of C sneaking in. Including the non-const'ness of the arguments of 
> that function, if you declare the arguments.
>

> But whether you can get away with mostly C on an interview or exam, when 
> the task is to code up a C++ program, well that's another matter 
> entirely...

I guess mostly they do not like it. And surely they have a point. But 
myself, I would not be so strict myself in my own coding that "everything 
must be C++ if its possible" especially if the C version is faster or better 
some other way. LIke somebody mentioned atoi is faster than strstream 
version (and this is what i also noticed with the stream in my code).

But surely certain things are "the truth" always. Like always use 
std::string instead of char[]. And always use vector instead of int[]. I did 
this change in my coding years ago. No longer char[] s. Many reasons... one 
being that if you add more code later, its easier to manage std::string. 
Also its surely faster.

But again, if it was a very small program, and am 100% sure its not gonna 
expand later, then why not use code like char[]- for strings if you feel so? 
Does not matter... 


0
no6909 (32)
11/21/2013 11:15:33 AM
On Thursday, 21 November 2013 10:22:17 UTC+2, crea  wrote:
> "=D6=F6 Tiib" <ootiib@hot.ee> wrote in message=20
> news:b1e33088-ae50-438d-9443-158e72597919@googlegroups.com...
> >> But this might be a real "problem" in a school assignments, or in a
> >> programming job interview, is asked to code something.
> >
> > Schools teach people the art of getting best grades out of
> > fellow person. That is important skill but persons differ so
> > we can not advice here without seeing particular individual.
> > Same skill matters in work interview as well, but the person
> > interviewing you is often smarter than the one in school so
> > be warned. ;)
> >
> > On any case it has nothing to do with similarities or
> > differences between C and C++.
>=20
> I mean that in C++ job interview they might as to write a C++ code. One=
=20
> might use partly C-style library functions, the other pure C++. But=20
> according to definition they both are actually C++ codes.

What interviewer more likely looks at is how you attack the problem
and safety and correctness of solution. If it compiles as C++ then
it is C++. Unfamiliar library or language is easy to learn for one
with programming skill.

>=20
> Maybe the thing is that if there is a C++ (library) version of certain=20
> code/function then that should be used instead of C version? So C library=
=20
> calls should be avoided always in C++ code (if just possible and there is=
 a=20
> C++ counter part)?

Avoid mixing.  Do not use <cstring> and <string> together or <cstdio>=20
and <iostream> together if possible.
0
ootiib (965)
11/21/2013 11:42:30 AM
On 21.11.2013 12:42, �� Tiib wrote:
>
> Avoid mixing.  Do not use <cstring> and <string> together or <cstdio>
> and <iostream> together if possible.

I think you mean (or they say nowadays, ITYM) <string.h> and <string> 
together, or <stdio.h> and <iostream> together.

Note, by the way, that in C++11 there's no longer even a formal reason 
to <cstdio> instead of <stdio.h>, and there are good reasons not to.


Cheers,

- Alf (nitpicking and anti-pattern mode)


0
usenet30 (890)
11/21/2013 11:47:12 AM
On Thursday, 21 November 2013 13:47:12 UTC+2, Alf P. Steinbach  wrote:
> On 21.11.2013 12:42, =EF=BF=BD=EF=BF=BD Tiib wrote:
> >
> > Avoid mixing.  Do not use <cstring> and <string> together or <cstdio>
> > and <iostream> together if possible.
>=20
> I think you mean (or they say nowadays, ITYM) <string.h> and <string>=20
> together, or <stdio.h> and <iostream> together.

I meant it is good to avoid usage of 'strlen()' and 'str.size()' in mix. Pe=
rsonally
I prefer latter since it performs better.

> Note, by the way, that in C++11 there's no longer even a formal reason=20
> to <cstdio> instead of <stdio.h>, and there are good reasons not to.

AFAIK the <csomething> headers include <something.h> and alias the
names in 'std' namespace. So people who want to have 'std::strlen' should
use <cstring>. Has something changed there? Personally I avoid it regardles=
s
of namespace.
0
ootiib (965)
11/21/2013 12:18:11 PM
On 21.11.2013 13:18, �� Tiib wrote:
> On Thursday, 21 November 2013 13:47:12 UTC+2, Alf P. Steinbach  wrote:
>> On 21.11.2013 12:42, �� Tiib wrote:
>>>
>> Note, by the way, that in C++11 there's no longer even a formal reason
>> to <cstdio> instead of <stdio.h>, and there are good reasons not to.
>
> AFAIK the <csomething> headers include <something.h> and alias the
> names in 'std' namespace. So people who want to have 'std::strlen' should
> use <cstring>. Has something changed there?

Yes.

In C++03 the headers were not allowed to do what you describe. E.g. with 
an implementation conforming in this regard (which AFAIK no 
implementation was, he he :), it was a feature much like "export") 
<cstring> would introduce std::strlen but not ::strlen. For brevity I 
give just the non-normative commentary from C++03 �D.5/3:

"Example: The header <cstdlib> provides its declarations and definitions 
within the namespace std. The header <stdlib.h> makes these available 
also in the global namespace, much as in the C Standard."

In C++11 they're finally allowed to pollute the global namespace, as you 
describe above and capturing the actual practice, as described by the 
corresponding C++11 �D5/3:

"Example: The header <cstdlib> assuredly provides its declarations and 
definitions within the namespace std. It may also provide these names 
within the global namespace. The header <stdlib.h> assuredly provides 
the same declarations and definitions within the global namespace, much 
as in the C Standard. It may also provide these names within the 
namespace std"

And then there's not even a formal advantage of using e.g. <cstring>: 
just problems, no advantage.

If someone absolutely want to write std::strlen then including <cstring> 
is the way to do that, yes. However, plain <string.h> may also introduce 
std::strlen, so that some code may compile on some implementation 
without including what's formally needed for general portability  -- 
which means added work when it's ported to a more strict implementation. 
Worse, code that does use the global namespace strlen (no qualification, 
which all C programmers and a great many C++ programmers are used to 
write and so are likely to write) will /most likely/ compile, but again 
may not compile with some more strict implementation, which again means 
added work  --  for no good reason.

In contrast, including <stdio.h> and writing just strlen has no 
potential portability problem and minimizes the number of things to know 
about (to wit, even you didn't recall exactly the detailed rules of 
<cstring> etc). It also makes programmers more familiar with what the C 
headers do place in the global namespace. Which, due to the pollution 
that you get in practice, they do need to be familiar with.


Cheers & hth.,

- Alf

0
usenet30 (890)
11/21/2013 2:21:27 PM
In article <gXlju.77200$Xe4.66168@fx34.am4>
	"crea" <no@com.notvalid> writes:
>
>"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> wrote in message 
>news:l6knej$3ki$1@dont-email.me...
>
>> But whether you can get away with mostly C on an interview or exam, when 
>> the task is to code up a C++ program, well that's another matter 
>> entirely...
>
>I guess mostly they do not like it. And surely they have a point. But 
>myself, I would not be so strict myself in my own coding that "everything 
>must be C++ if its possible" especially if the C version is faster or better 
>some other way. LIke somebody mentioned atoi is faster than strstream 
>version (and this is what i also noticed with the stream in my code).

What this comes down to, and many of the answers are brushing
against, is that you are not asking about the C++ language.  You
are asking about (for lack of a better term) "C++ culture."

The problem there is that "C++ culture" is not a single thing.
Different projects, different groups, etc. have different preferences.

Last job, I worked with a guy who tried to put in every boost feature
that he could.  Most of the rest of the team stuck with mostly
non-boost solutions.  Both are valid ways, but this didn't make for
a good fit.

Without knowing the local culture, you can't predict the preferences.
What you *can* do is talk about what you are doing.  When you put
in something that could go either way, talk around which you chose
-- "Foo items[2]; -- that could be a vector, but there are only two
that you toggle between . . . ."

Coding in an interview is not often about the final code.  It is
about determining:
  1)  Does he understand the problem?
  1a) If not, was his understanding reasonable?
  2)  Does the code solve the problem as he understood it?
  3)  Does his approach -- top-down, bottom-up, inside-out, etc.
      -- seem good, or is it confused?
and so on.


I once had a code test for a C job.  One of the problems was reversing
the order of the bits in the input.  I wrote my solution, talking
it through while writing, finishing up with, "and [brief pause] it
is the same as the input."  I had one of the operations (or one of
the loops, been a while) backwards.  The important thing was that
I caught it and understood why it was wrong.

I got the job.

-- 
 Drew Lawson               While they all shake hands
			   and draw their lines in the sand
			   and forget about the mess they've made
0
drew20 (85)
11/21/2013 3:20:42 PM
On Thu, 2013-11-21, crea wrote:
....

> I guess mostly they do not like it. And surely they have a point. But 
> myself, I would not be so strict myself in my own coding that "everything 
> must be C++ if its possible" especially if the C version is faster or better 
> some other way. LIke somebody mentioned atoi is faster than strstream 
> version (and this is what i also noticed with the stream in my code).

Prefer strtol() and related functions; unlike atoi() they can
detect parse errors.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .
0
nntp24 (1801)
11/21/2013 11:31:11 PM
"Drew Lawson" <drew@furrfu.invalid> wrote in message 
news:l6l8ca$2u5l$2@raid.furrfu.com...
> In article <gXlju.77200$Xe4.66168@fx34.am4>
> "crea" <no@com.notvalid> writes:
>
> What this comes down to, and many of the answers are brushing
> against, is that you are not asking about the C++ language.  You
> are asking about (for lack of a better term) "C++ culture."

Ye

>
> The problem there is that "C++ culture" is not a single thing.
> Different projects, different groups, etc. have different preferences.
>
> Last job, I worked with a guy who tried to put in every boost feature
> that he could.

:)

Most of the rest of the team stuck with mostly
> non-boost solutions.  Both are valid ways, but this didn't make for
> a good fit.

Ye, I guess there should be some agreement how things are done and not 
everybody doing their own way.
The culture in a software company where I was, was that everybody was really 
just doing their own thing. Like is doing C++ projects and one person coding 
using only C style but other using C++ and classes. There is gonna be 
problems at some point when combining the codes.

>
> Without knowing the local culture, you can't predict the preferences.
> What you *can* do is talk about what you are doing.  When you put
> in something that could go either way, talk around which you chose

> -- "Foo items[2]; -- that could be a vector, but there are only two
> that you toggle between . . . ."

Ye. Even here there could be an argument though to use vector instead. Both 
could be ok...but ye, its a matter of discussion and people who understand 
how to code correctly. People who do not understand correct way of coding 
can confuse the group though. I dont think so much about how much everybody 
can do how they like but rather how it blends with the whole group as its a 
group efford anyway.

> I once had a code test for a C job.  One of the problems was reversing
> the order of the bits in the input.  I wrote my solution, talking
> it through while writing, finishing up with, "and [brief pause] it
> is the same as the input."  I had one of the operations (or one of
> the loops, been a while) backwards.  The important thing was that
> I caught it and understood why it was wrong.
>
> I got the job.

Ye, sure thats not a big issue. 


0
no6909 (32)
11/22/2013 7:34:44 AM
"Jorgen Grahn" <grahn+nntp@snipabacken.se> wrote in message 
news:slrnl8t5tu.hj3.grahn+nntp@frailea.sa.invalid...
> On Thu, 2013-11-21, crea wrote:
> ...
>
>> I guess mostly they do not like it. And surely they have a point. But
>> myself, I would not be so strict myself in my own coding that "everything
>> must be C++ if its possible" especially if the C version is faster or 
>> better
>> some other way. LIke somebody mentioned atoi is faster than strstream
>> version (and this is what i also noticed with the stream in my code).
>
> Prefer strtol() and related functions; unlike atoi() they can
> detect parse errors.
>

ok, but still point being that we would use C-function rather than C++ one.

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


0
no6909 (32)
11/22/2013 7:38:21 AM
crea <no@com.notvalid> wrote:
> ok, but still point being that we would use C-function rather than C++ one.

Calling it a "C-function" is a bit misleading.

Since said function is specified in the C++ standard, that makes it a
100% C++ standard function. Yes, it's the exact same function as
specified in the C standard (and many/most C++ compilers will even use
the exact same binary implementation when compiling in both modes),
but since it's a function defined in the C++ standard, that technically
speaking makes it also a C++ function.

There's nothing wrong in using a function defined in the standard.
If someone tells to you "you should be using the C++ version of that
function", you can simply answer them "but I *am* using the C++ version
of the function; it's right there, clearly defined in the C++ standard."

If you want to use std::atoi() or std::strtol(), go right ahead. There's
nothing wrong with them. As long as you know how to use them safely,
I see absolutely no problem.

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
0
nospam270 (2948)
11/22/2013 10:38:12 AM
"Jorgen Grahn"  wrote: 
> Prefer strtol() and related functions; unlike atoi() they can
> detect parse errors.

C++11:
int stoi(const string& str, size_t *idx = 0, int base = 10);

-- 
Jouko

0
11/22/2013 5:59:31 PM
On Fri, 2013-11-22, Jouko Koski wrote:
> "Jorgen Grahn"  wrote: 
>> Prefer strtol() and related functions; unlike atoi() they can
>> detect parse errors.
>
> C++11:
> int stoi(const string& str, size_t *idx = 0, int base = 10);

Good -- although I would have preferred a templated one which worked
on [begin, end) pairs. (Perhaps there is one; I am too lazy to check.)

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .
0
nntp24 (1801)
11/22/2013 6:18:44 PM
"Juha Nieminen" <nospam@thanks.invalid> wrote in message 
news:l6nc6k$161g$1@adenine.netfront.net...
> crea <no@com.notvalid> wrote:
>> ok, but still point being that we would use C-function rather than C++ 
>> one.
>
> Calling it a "C-function" is a bit misleading.
>
> Since said function is specified in the C++ standard, that makes it a
> 100% C++ standard function. Yes, it's the exact same function as
> specified in the C standard (and many/most C++ compilers will even use
> the exact same binary implementation when compiling in both modes),
> but since it's a function defined in the C++ standard, that technically
> speaking makes it also a C++ function.

ye agree. Although sometimes in school they might want to use some 
class-system to do it more "elegantly". 


0
no6909 (32)
11/23/2013 11:47:12 AM
"Jouko Koski" <joukokoskispam101@netti.fi> wrote in message 
news:0YMju.11197$t02.1949@uutiset.elisa.fi...
> "Jorgen Grahn"  wrote:
>> Prefer strtol() and related functions; unlike atoi() they can
>> detect parse errors.
>
> C++11:
> int stoi(const string& str, size_t *idx = 0, int base = 10);

oh, ok. Still solves all the problems.. :) 


0
no6909 (32)
11/23/2013 11:48:39 AM
Reply:

Similar Artilces:

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta > * open source - preferable, but not 100% necessary what's wrong with using C? Friedrich > what's wrong with using C? Too low level, no built-in garbage collection. -- Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: >> what's wrong with using C? > > Too low level, Well the Smalltalk people say, have a small language and a big library. I assume C's library status beyond that of Smalltalk. > no built-in garbage collection. Use the Boehm Weisser GC. Friedrich "Kevin Albrecht" <kevin@albrecht.net> wrote in message news:<2TiYb.237892$rj7.1641209@twister.tampabay.rr.com>... > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) > ...

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

slime C-c C-c annoyance
Does anyone have a good workaround for this problem other than: just be careful! When I've compiled a large package and slime has given me a *slime-compilation* buffer, I like to work through this buffer issue by issue, fixing the errors, warnings, etc. But If I ever press C-c C-c in the editor window while fixing an error, slime destroys the *(slime-compilation* buffer with the compilation output of C-c C-c. Jim Newton <jimka.issy@gmail.com> writes: > Does anyone have a good workaround for this problem other than: just be careful! > > When I've compiled a ...

C as a Subset of C++ (or C++ as a superset of C)
Isn't it a lame use of human time and effort to maintain completely separate C and C++ standards? As in the words of Betty White about Facebook: "It seems like an incredible waste of time". Why don't the two standards groups get together and agree on a common specification for the ground which both standards cover? There would still be two separate standards, but they'd both be exactly the same for the common ground. The common ground document could be referred to by both standards instead of being maintained by both groups in individual efforts resulting in...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

c,c++,obj-c
Of the 3 languages titled in this post is c++ older than obj-c ? Would someone experienced in C be able to dive right into C++ rather than obj-c ? Java is out for me now except applet programming I think I'm going to go with just C and C++. Bill Bill Cunningham wrote: > Of the 3 languages titled in this post is c++ older than obj-c ? Why does that matter? Do you want to use an old language? Try Fortran or LISP. > Would > someone experienced in C be able to dive right into C++ rather than > obj-c ? Not quite dive in, at least not into the OO parts of C++. ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! Throne Software wrote: > Throne Software has opened up C, C++ and C# Forums at: > > http://www.thronesoftware.com/forum/ For all of your forums newsgroups already exist. > Join us! Why? Don't see any reason to support your marketing. ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! In article <1120963701.862698.160260@g14g2000cwa.googlegroups.com>, Throne Software <mail@thronesoftware.com> writes >Throne Software has opened up C, C++ and C# Forums at: > >http://www.thronesoftware.com/forum/ > >Join us! Why? The beauty of news groups is that they come to me I don't have to go to them. Also all the people who have been around a while know what they are doing and are here. I noticed that there are some C and C++ Forums on another system. Full of the blind (opinionated) leading the blind. The problem is that as the experienced people who have been around a long while are on usenet. the system works. Why move. Certainly not to a forum on a commercial web site. The web site might go down. Usenet can't. Web based systems are not as safe. I have to trust you about cookies and all sorts. (active X etc). Usenet is international and independent. It is not controlled by anyone. Why would anyone move from this system to a web based one in a a rogue state? There is no point in running a web based forum except as a support forum for your own products. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Chris Hills wrote: > In article <1120963701.862...

C,, C++, Java, C#
I come from C,C++,Java and C#. What can SmallTalk do for me and for what cost? Regarding the Squeak thing, it's interesting though confusing. Is it an IDE? Why are the menus so wacky? "DM McGowan II" <nospam@nospam.net> wrote in message news:PLednX2vnLd11IncRVn-rA@comcast.com... > I come from C,C++,Java and C#. What can SmallTalk do for me ...? Ask not what Smalltalk can do for, but what can you do with Smalltalk. :-) In very few words, it significantly reduces time to market, while enhancig the development experience. This is because: 1. It manages the memory for you, so you don't have to allocate/deallocate all the time (the source of some of the most nasty bugs in C). Java and C# learnt that feature from ST. 2. It has single inheritance. 3. All the development is in a single file, called the image, so you don't have to fish for where did you put that missing class. Yet, you don't have to go through thousands of lines of code to find the method you wrote three months ago. 4. It's the language for which it's easier to work within the Agile methodologies. 5. It's strongly typed without being unnecessarily redundant. 6. It's "wacky" interface releases you from the need to use curlys. 7. It comes with a huge library, so you don't need to reinvent the wheel as much. 8. It's debugger is highly integrated and friendly, so the experience of findin...

C and C
Please Who wants to post Command and Conquer Red Alert 3. I'm looking for the whole version. If you do so Thank you. --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- Shaniel's Usenet wrote: > Please > Who wants to post Command and Conquer Red Alert 3. > I'm looking for the whole version. > If you do so Thank you. > > > --------------= Posted using GrabIt =---------------- > ------= Binary Usenet downloading made easy =--------- &g...

More about C and C++
Hello, I have wrote: >I will resume it like this: >On the criterias of "complexity" and "difficulty", the C and C++ >programming languages are more complex and difficult than Object >Pascal for example, so since they are more complex and difficult they >are likely to create something like a darwinian filter who don't let >the weaker humans among us humans to cross or to climb the social >ladder, this is why i think that C and C++ do participate to social >darwinism, this is why i say that C and C++ are bad. Joseph ...

C to C++
Hi all In C I have previously created structures that contain themselves e.g. typdef struct Node_tag { struct Node_tag ptrNodes; float nodeNumber } Node; This worked fine, but trying to do the same in C++ doesn't work, any suggestions. Thanks daveR This day of Fri, 30 Apr 2004 10:39:02 +0100, "Charlotte Dean" <charlottedean@(NO5PAM)sheffield17a.fsnet.co.uk> proclaimed: >Hi all > >In C I have previously created structures that contain themselves e.g. > >typdef struct Node_tag { > ...

c++ to c
Hello Everyone, I have a project where I need to write C++ code in C (due to OS issues). Can someone please show me exactly what I need to do to convert the code to C. Thanks Jami Here is the code I need to convert to C++: class CTestSuite : public CTestSuiteBase { public : CTestSuite(CTestBase *aTest); virtual ~CTestSuite(); virtual TInt InvokeTestL(int argc, char * argv[], TTestConfig * aConfig) ; IMPORT_C CTestSuite *GetTestSuite(); virtual int RunTestL(int aArgc, char *aArgv [], TTestConfig *aConfig); protected: CTestBase *iTest; } ; class CTestSuiteBase : p...

c++/c#
hello all experiancesd techies, i am a final yr engg student with knowledge of c++ n java. i want to start windows programing, n hence have to decide whether to choose my language as c++ or c#. please guide me which language would benefit in the long run, if i intend to persue a job in a product development company/( like adobe) after graduation,(not in a consultancy like acenture). also suggest me good books for that. thanx a lot pravin.chaudhary wrote: > hello all experiancesd techies, > i am a final yr engg student with knowledge of c++ n java. This is USENET, not...

C and C++
Hello, I have been having trouble getting used to C. A very simple language. Could this be because I was very familiar with C++ before trying to learn C? The fstream header is so simple. using fopen, fread and fwrite for example seems complicated. Bill "Bill Cunningham" <nospam@nspam.com> writes: > I have been having trouble getting used to C. A very simple > language. Could this be because I was very familiar with C++ before trying > to learn C? The fstream header is so simple. using fopen, fread and fwrite > for example seems compli...

More about C and C++
Hello, I have wrote: >I will resume it like this: >On the criterias of "complexity" and "difficulty", the C and C++ >programming languages are more complex and difficult than Object >Pascal for example, so since they are more complex and difficult they >are likely to create something like a darwinian filter who don't let >the weaker humans among us humans to cross or to climb the social >ladder, this is why i think that C and C++ do participate to social >darwinism, this is why i say that C and C++ are bad. Josep...

About C and C++
Hello... I have saw some programmers talking about C on the C's forums... But as you have seen me talking before on my post titled "Software life cycle" , you have noticed that i have talked about the criterions that is "Maintainability" and "modifiability", what i don't like in C is that if you want to group efficiently functions and some propoerties that are shared inside an object , you can not do that efficiently as can do Object Pascal or C++, if you are writing in C you have to use global variables, but that's not good for "m...

c++ or c#
hello all experiancesd techies, i am a final yr engg student with knowledge of c++ n java. i want to start windows programing, n hence have to decide whether to choose my language as c++ or c#. please guide me which language would benefit in the long run, if i intend to persue a job in a product development company/( like adobe) after graduation,(not in a consultancy like acenture). also suggest me good books for that. thanx a lot <pravin.chaudhary@gmail.com> wrote in message news:1131971088.291580.42500@g47g2000cwa.googlegroups.com... > i am a final yr engg student with ...

c++/c
hi i have been recently told that there is no exception handling ic c+ +.?? as far as i remember i have read, it has. also java has exception handling for sure but there we can use finally also which we cant use in c ++. what other differences do we have in the two languages c++ and java in exception handling. and which one is better? rupika wrote: > > i have been recently told that there is no exception handling ic > c++.?? You should ask about C in comp.lang.c, about C++ in comp.lang.c++. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home...

C++ or C?
I am new to MPI and have a basic understanding of C and C++. So I was wondering if any of you guys with experience in using MPI had any pointers with regards choosing either C or C++. I intend to use MPI in parallelizing code I have that was written in Java. So obviously the Java code it is heavly object orientated. With regards parallelizing it; right now I think it will mainly be a Master-Slave style of design with no inter-process communication needed once the master has sent the work to the slave. Most, if not all, of my communications will involve simply sending a large object from the ...

About C and C++
Hello, I will resume it like this: On the criterias of "complexity" and "difficulty", the C and C++ programming languages are more complex and difficult than Object Pascal for example, so since they are more complex and difficult they are likely to create something like a darwinian filter who don't let the weaker humans among us humans to cross or to climb the social ladder, this is why i think that C and C++ do participate to social darwinism, this is why i say that C and C++ are bad. Thank you, Amine Moulay Ramdane. On Sun, 08 Jun 2014 06:1...

Web resources about - Is this C or C++? - comp.lang.c++

How would a Donald Trump presidency affect the stock market?
What would President Trump mean for the stock market? Once a far-fetched notion, the question is becoming serious business for investors now ...

Manning changed the way we play, and watch, football
To find the true measure of what Peyton Manning meant to football, don't bother poring over the highlights from his record 186 wins, or re-watching ...

Suicide Attack at Pakistani Court Compound Kills Over a Dozen
New York Times Suicide Attack at Pakistani Court Compound Kills Over a Dozen New York Times PESHAWAR, Pakistan — Sixteen people were killed ...

First ever OS X ransomware encrypts your data and asks for money
Ransomware is a particularly nasty piece of malware: After your computer is infected, it encrypts your data and refuses to give you the key unless ...

Email pioneer and @ symbol inventor Ray Tomlinson dies aged 74
We might have witnessed the meteoric rise of instant messaging in modern times, but email remains a critical aspect of communication today. The ...

North Korea’s Threats Trigger Cautious Strongarm Diplomacy
With news about the frequent and the latest threat from North Korea, is the question of whether regional powers can do anything about it. In ...

Body found in elevator weeks after power cut
WDBJ7 Body found in elevator weeks after power cut WDBJ7 A 43-year-old woman was found dead in an elevator in China after possibly being trapped ...

EU leaders to press Turkey, back Greece at migrant summit
BRUSSELS (AP) — European Union leaders arrived in Brussels Monday to press Turkey to do more to stop migrants from entering Europe and to shore ...

'Downton Abbey' fans deal with their grief by imaging hilarious alternate endings
The UK may have said goodbye to Downton Abbey back in December but the wound is all too fresh for fans in the U.S., who bid farewell to the Abbey ...

A battle has begun on 'The Walking Dead'
WARNING: This post contains spoilers from the latest episode of The Walking Dead . Count me among those who thought this week's episode of The ...

Resources last updated: 3/7/2016 12:06:05 PM