Hi all,
I'm very new to C++. is strcmp considered a C++ function ?
what are the differences between using these 2 comparison ?
if (strcmp (var,"string") == 0)
if (var=="string") ?
Thanks in advance
Hi all,
I'm very new to C++. is strcmp considered a C++ function ?
what are the differences between using these 2 comparison ?
if (strcmp (var,"string") == 0)
if (var=="string") ?
Thanks in advance
strcmp compares C style strings, that is, char * or char[].
== compared C++ style strings, that is, std::string.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
Thanks thats a quick one. I'm trying to program in C++ , i have some knowledge in C. Would it be appropriate to mix codes from 2 different languges ?Originally Posted by Cat
When you are firmly grounded in both -- otherwise it just confuses you and screws you up in either.Originally Posted by yuliang11
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Thanks. in that case i'll just C all the way.thanks all for your helpOriginally Posted by Dave_Sinkula
It is possible to do so, but unadvised. Using C++ strings is generally easier, so you should learn and use them.Originally Posted by yuliang11
But sometimes you are forces to work with the lower level c strings. For example command line arguements are always c strings. (of course you can still convert them to C++ string easily)
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
If you're learning C++ then you're going to need to try to forget what you know about C and learn a new way of thinking.Originally Posted by yuliang11
Don't progam in "C++--". That is, don't write code that's really C code with a few C++ things added in.
95% of all cases in which you use a string, you can use std::string safely (and in the last 5% you should prefer std::vector<char> over char[] anyhow).
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.