Search code examples
c++c++11stdstring

No instance of overloaded function toupper matches the argument list


I am trying to use toupper to convert first letter to uppercase in string but it keeps showing error code below:

no instance of overloaded function"toupper"matches the argument list

Code:

#include<iostream>
#include<cstring>
#include<cctype>
using namespace std ;

int main()
{
    string s("some string");

    if(s.begin() != s.end()){
        auto c = s.begin();
        c = toupper (c);
    }
    return 0 ;
}

Solution

  • Dereferencing the iterator with * operator will do the work:

    *c = toupper (*c);