Can I get a non-const C string back from a C++ string?

前端 未结 13 1294
借酒劲吻你
借酒劲吻你 2020-12-01 15:33

Const-correctness in C++ is still giving me headaches. In working with some old C code, I find myself needing to assign turn a C++ string object into a C string and assign i

13条回答
  •  忘掉有多难
    2020-12-01 16:10

    In CPP, if you want a char * from a string.c_str() (to give it for example to a function that only takes a char *), you can cast it to char * directly to lose the const from .c_str()

    Example:

    launchGame((char *) string.c_str());
    

提交回复
热议问题