I'm pretty noobish when it comes to the string class - I used to use char* all the time until otherwise informed. So how would I convert a string to char*? Although best avoided, would this method *work*:
I just tapped that out off the top of my head so it's probably either wrong or very noob-esque.Code:string str; char* other_str; cin >> str; other_str = new char[str.size() + 1]; // would this work? strncpy (other_str, reinterpret_cast<char*> (str), str.size()); delete [] other_str; // etc...
I would like to know how to do this in case I need to, for example, read user input into a string instance, then pass it to an fopen call (or whatever takes a char*).