Maulrus Maulrus - 1 year ago 69
C++ Question

Is there any way to pass a std::string to a function that accepts a char* and changes its contents?

I'm trying to get back into programming, specifically console games. I'd heard that curses was good for that, so I found a curses tutorial and I'm getting into that. I'm using C++, and naturally I wanted to take advantage of std::string, but functions like

only accept char*. Is there any way to pass a string as a char*, or am I gonna have to forgo using C++ strings?

Answer Source

You can still use C++ std::string, but you'll have to copy the contents into a buffer (std::vector<char> would be good) and copy it back when using functions that expect a writable char* buffer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download