Search code examples
c++operatorsfilestream

How to fix 'no match for 'operator=='' when comparing strings in if statement


Trying to compare strings using if statements but getting operator errors. How can I fix this to make the statement compare the strings? Using Code::Blocks as compiler.

Full Raw code Pastebin: https://pastebin.com/DJGqJBwu (No longer public due to question solved)

(NOTE: Most of the commenting in raw code is for experimenting and there are tons of errors overall that I can go over later)

This is for a leaderboard I am trying to create for a Tic-Tac-Toe game. I have tried different ways to compare the strings to fix this such as .compare.

void admin (string names, int nameW[10], int wins[10], unsigned int a[10]) //called variables from main
{
    char repeat = 'y'; //used for function loop
    char resetAll; //used elsewhere
    int winCount; //used elsewhere
    string reset;
    string modify; //used elsewhere
    string admin; //used elsewhere

    cin >> reset;

        //Reset
        if (reset==names[0])
        {
            wins[0] = 0;
        }
}

Build log:

error: no match for 'operator==' (operand types are 'std::__cxxll::string {aka std::__cxll::basic_string<char>}' and '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}')

I am expecting the reset variable to be the same as the names[0] variable so that the code can execute. Results are that code cannot build and run (unable to test program).


Solution

  • The problem was the admin function parameter where the string "names" did not declare the array.

    Turn:

    void admin (string names, ...
    

    Into:

    void admin (string name[10], ...