vendredi 24 février 2017

C++ error, compiler won't recognize string::push_back

The function it has an issue with:

string encode (string message, string key) {

    string code = "whatever";
    string forst;
    int num;
    string::size_type begin = 0;

    message = lower_and_strip(message);

    for (char val : message) {
        num = return_encoded_char(key, begin, val);
        forst = to_string(num);
        code.push_back(forst); //*******************************
    }


    return code;
}

The starred line is what it points to. The return_encoded_char function returns an integer.

The specific error is proj05.cpp:68:23: error: no matching function for call to 'std::basic_string<char>::push_back(std::string&)' and points to the line I starred.

I initially just declared code without initializing it, but changing that didn't fix it. All the similar questions I could find had some other element to blame; I feel like this should be relatively straightforward, though obviously it's not since it isn't working.

I have #include <stream> and using std::to_string etc. I'm using -std=c++11 to compile it.

Help.

P.S. Using Geany on Linux.

Aucun commentaire:

Enregistrer un commentaire