1

Possible Duplicate:
Convert std::string to const char* or char*

Simple question but I'm new to C++. How do I convert a string to a char * (I read a string from cin then I have a function that operates on char[] so need to get a char *)? Thanks.

Community
  • 1
  • 1
tree-hacker
  • 5,351
  • 9
  • 38
  • 39

2 Answers2

3

See How to convert a std::string to const char* or char*?.

Community
  • 1
  • 1
Hexagon
  • 6,845
  • 2
  • 24
  • 16
2

You want c_str().

Tristan
  • 916
  • 5
  • 10
  • Note that c_str() gives a 'const char *', not a 'char *'. May not be useful, and could be dangerous if used incorrectly. – Hexagon Dec 09 '10 at 04:52