This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]