View Full Version : Cannot convert from const char to const char*
Aranince
Sep 29, 2008, 03:28 PM
I'm trying to get a char from an std::string and see what it's value is. The error is on the line of the if statement. Cannot convert from `const char' to `const char*'
const char done = taskdata.at(1);
if(strncmp(done, "*", 1) == 0)
m_done = true;
else
m_done = false;
iSee
Sep 29, 2008, 03:35 PM
strncmp is for comparing strings of characters. To compare one character to another, you can just do it directly:
if (done == '*')
m_done = true;
else
m_done = false;
or even just:
m_done = (done == '*');
Notice how a character literal is surrounded by single quotes (while a string literal is surrounded by double-quotes).
Aranince
Sep 29, 2008, 03:39 PM
Awesome! Thanks for your help.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.