mercredi 5 mai 2021

Is there any way to tell C++11 to use std::string instead of const char*?

Im trying to migrate code from another language that allows concatonation of strings with the '+' operator.

//defintion 
void print(std::string s) {
    std::cout << s;
}
//call
print("Foo " + "Bar");

The issue I'm having is that c++ sees "Foo " and "Bar" as const char* and cannot add them, is there any way to fix this. I have tried including the string library to see if it would change them automatically but that didnt seem to work.

Aucun commentaire:

Enregistrer un commentaire