string class :: how to get char* from a string object

Jyotirmoy Das Jyotirmoy_Das@infosys.com
Tue Nov 18 05:34:00 GMT 2003


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
  



More information about the Gcc-help mailing list