easy question

M

max

Hi,
I'm verry new to cpp ( I think im using only C but n e way ) in my prog
I need a user to input a choice with cin >> myvar. Actually
mymar is type char but when I type something higher than 1 character, the
program just quits right away. What can I do to prevent this and not
having to play with char array ?

TIA,
Max.
 
M

Mike Wahler

max said:
Hi,
I'm verry new to cpp ( I think im using only C but n e way )

You need to find out which. C and C++ are distinct,
separate languages.
in my prog
I need a user to input a choice with cin >> myvar. Actually
mymar is type char but when I type something higher than 1 character, the
program just quits right away.

Must be that bug on line 37.
What can I do to prevent this and not
having to play with char array ?

Use a std::string with std::getline

Oh, and if you show us your code, we can determine
what the problem really is.

-Mike
 
J

John Carson

Mike Wahler said:
You need to find out which. C and C++ are distinct,
separate languages.

Stroustrup seems to be confused too. On p.21 of TC++PL we read:

"2.1 What is C++
C++ is a general-purpose programming language with a bias towards systems
programming that
- is a better C "
 
G

Gary Labowitz

John Carson said:
Stroustrup seems to be confused too. On p.21 of TC++PL we read:

"2.1 What is C++
C++ is a general-purpose programming language with a bias towards systems
programming that
- is a better C "

Are you thinking that by saying C++ is a better C that Stroustrup is saying
the C++ language is a C language, only better?
You might just as easily say "A claw hammer is a better nail-driving device
than a screwdriver" means a claw hammer is a screwdriver, only better.
I think this is more in the context of what he means, i.e. C++ is better at
systems programming than C.
 
J

John Carson

Gary Labowitz said:
Are you thinking that by saying C++ is a better C that Stroustrup is
saying the C++ language is a C language, only better?
You might just as easily say "A claw hammer is a better nail-driving
device than a screwdriver" means a claw hammer is a screwdriver, only
better.
I think this is more in the context of what he means, i.e. C++ is
better at systems programming than C.


No, what he means is that you can use C++ for C-style programming if you
want, and that for this purpose C++ is a better language than C (better type
safety, for example). Of course, C++ offers many features that are missing
from C and, of course, Stroustrup would say that it is generally better to
make use of them.

The point of my original post (expressed in an ironic style) was that I
believe that the OP was saying that he was programming in C++ but in a C
style --- exactly what Stroustrup was talking about. Accordingly, there was
no basis for suggesting that he was confused about the fact that C and C++
are different languages, just as it would be absurd to suggest that
Stroustrup was confused on the question.

Some people in this newsgroup have what seems to me to be a religious
obsession about distinguishing C and C++. Of course they are different
languages, but maintaining backwards compatibility with C was one of the
fundamental design goals of C++. Accordingly, it is quite natural, even
though not strictly correct, to refer to "programming in C" or "using only
C" when using C++ for C-style programming. Such phrases, strictly speaking,
are metaphors, but some people seem unfamiliar with metaphors or think they
should be banned.
 
G

Gary Labowitz

With all this there seems to be a little joke. C++ tried to be backward
compatible with C. Then C changed. Is C++ still backward compatible with a
language that has moved on?
Maybe I should be banned. Anyway, thanks for the clarification.
 
J

John Carson

Gary Labowitz said:
With all this there seems to be a little joke. C++ tried to be
backward compatible with C. Then C changed. Is C++ still backward
compatible with a language that has moved on?

This is apparently a matter of ongoing debate within the Standards
committees for the two languages. There are some who want to reconcile C99
and C++ and some who want to ignore the recent changes to C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top