Cannot convert from const char to const char*

Discussion in 'Mac Programming' started by Aranince, Sep 29, 2008.

  1. Aranince macrumors 65816

    Joined:
    Apr 18, 2007
    Location:
    California
    #1
    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*'

    Code:
        const char done = taskdata.at(1);
        if(strncmp(done, "*", 1) == 0)
            m_done = true;
        else
            m_done = false;
     
  2. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    strncmp is for comparing strings of characters. To compare one character to another, you can just do it directly:

    Code:
    if (done == '*')
      m_done = true;
    else
      m_done = false;
    
    or even just:

    Code:
    m_done = (done == '*');
    Notice how a character literal is surrounded by single quotes (while a string literal is surrounded by double-quotes).
     
  3. Aranince thread starter macrumors 65816

    Joined:
    Apr 18, 2007
    Location:
    California

Share This Page