This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
string class :: how to get char* from a string object
- From: "Jyotirmoy Das" <Jyotirmoy_Das at infosys dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Tue, 18 Nov 2003 11:03:16 +0530
- Subject: string class :: how to get char* from a string object
Hi,
I have two question.
1) What will be the best way to get char * from a string. Whether this is a good option?
string str("abcdef");
char * cstr = const_cast<char *> str.c_str() ;
Problem is that, then user can modify the cstr which in turn modify the str object. That is not desirable.
2) If i do the following ::
string str("abcdef");
Whether string class will append a '\0' after storing the 'abcdef' or not ?
What will be the capacity of the above string object ? Why it is not the same as no. of character of "abcdef" ?
Thanking you,
Jyotirmoy Das
jyotirmoy_das@infosys.com