mardi 23 juin 2015

Inline char to std::string conversion

Is there a built-in method for constructing a std::string based on a given char?

The reason I ask this is because I want to make a function call directly within the if statement:

// Given function prototype
bool func(std::string s);

for(auto rit = s.rbegin(); rit != s.rend(); ++rit)
{
    if(func(*rit))
    {
        //
    }
}

I've tried the following:

std::string(*rit)
static_cast<std::string>(*rit)

Aucun commentaire:

Enregistrer un commentaire