如何将std :: basic_string类型转换为char类型的数组? [英] How can I convert a std::basic_string type to an array of char type?
问题描述
运行此代码时出现以下错误:
syslog(LOG_ERR | LOG_USER,%s,errorString );
无法转换'const string {aka const std :: basic_string}' 'int char,const char *'for> argument'2'to'void syslog(int,const char *,...)'inServer.cpp / PeCounter
line 478 C / C ++ Problem
当我使用cout输出到stdio时,我对程序进行了守护进程,并且errorString值打印得很好,但是在使用syslog调用时它不会打印。 / p>
以'const char'的形式获取std :: basic_string(char)。
Nevermind,I STW,发现basic_str有一个项目访问方法c_str,似乎修复了编译问题。
到网站: http://en.cppreference.com/w/cpp/string/basic_string
I get the following error when this code is run:
syslog(LOG_ERR | LOG_USER, "%s",errorString);
cannot convert ‘const string {aka const std::basic_string}’ to ‘const char*’ for >argument ‘2’ to ‘void syslog(int, const char*, ...)’ inServer.cpp /PeCounter
line 478 C/C++ Problem
I am daemonizing the program and the errorString value prints just fine when outputted to stdio using cout, but it will not print when using a syslog call.
Any way to get std::basic_string(char) into the form of 'const char'.
Nevermind, I STW and found that basic_str has an item access method c_str which seems to fix the compile issue.
Here is the URL to the site: http://en.cppreference.com/w/cpp/string/basic_string
这篇关于如何将std :: basic_string类型转换为char类型的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!