Sunday, 18 February 2018

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



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'.


Answer



I found that std::basic_string has an item access method c_str() which seems to fix the compiling issue.



Here is a site with more information: http://en.cppreference.com/w/cpp/string/basic_string



No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...