C++ deprecated conversion from string constant to 'char*'

前端 未结 11 1370
傲寒
傲寒 2020-11-22 16:01

I have a class with a private char str[256];

and for it I have an explicit constructor:

explicit myClass(const char *func)
{
    strcpy(         


        
11条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 16:50

    For what its worth, I find this simple wrapper class to be helpful for converting C++ strings to char *:

    class StringWrapper {
        std::vector vec;
    public:
        StringWrapper(const std::string &str) : vec(str.begin(), str.end()) {
        }
    
        char *getChars() {
            return &vec[0];
        }
    };
    

提交回复
热议问题