stupid chars

Started by
13 comments, last by technomancer 19 years, 5 months ago
c_str() returns a const char pointer - it does not take any params. It works like so:

// your std stringstd::string myStr = "blah";// Assing your const char pointerconst char *strPtr = myStr.c_str();


then you can use strPtr as you see fit - although it is const so you can't edit it. If you want to edit it just use the myStr var and all the handy overloaded operators!
Advertisement
Hi,

This is all you do:

string name = "Hello World!";

Then to convert it to char would be name.c_str();

Also include <string> (not string.h)

Later,

GCS584

[EDIT:] Someone beat me too it! Don't pass any parameters to the function.
i win :)
I love strings :) I can use chars but strings have everything built in right at your fingertips. Like mentioned above the problems that I see are when a function from a library is set to take in a char as an argument and it denies your string lol [smile] Althought there are probably methods in the string class to get around this I'm lazy [smile]
-Goten
I personnally prefer using STL std::string and std::stringstream over char arrays as it prevents one of the biggest kickers in software development buffer over/underrun. I don't mind M$ CString classes either for the same reasons.

This topic is closed to new replies.

Advertisement