How can I convert a std::basic_string type to an array of char type?

后端 未结 2 1912
情歌与酒
情歌与酒 2021-02-15 01:06

I get the following error when this code is run:

syslog(LOG_ERR | LOG_USER, \"%s\",errorString);

cannot convert ‘const string {a

2条回答
  •  甜味超标
    2021-02-15 01:26

    The c_str() or data() member function provides a pointer to the first element of an array of char_type which contains your string. It's valid as long as the string object itself remains valid and unchanged (but beware that operations that may cause reallocations may invalidate the pointer -- best not to store it).

提交回复
热议问题