I want to make a pair of int and string. As:
pair<int,string> car ;
car.first = 10;
car.second = 'Sarim';
cout<<car.first<<endl;
cout<<car.second;
I want to make a pair of int and string. As:
pair<int,string> car ;
car.first = 10;
car.second = 'Sarim';
cout<<car.first<<endl;
cout<<car.second;
Use
car.second = "Sarim";
The second of the pair is an std::string
, not a character, hence you can provide an std::string
or const char*
to be used to construct one.
Note that the single quotes are for characters while the double ones I used make a const char*
which can be used to construct an std::string
r.second = 'Sarim';
is wrong. Single quotes are used for character constants and what you have there is not a single character.
You want
r.second = "Sarim";
for a multiple character literal.
A string in C++ is marked using double-quotes ("
), the single quotes mark a character (hence only one character is stored). The warning is here to tell you that your “character” is too big (and indeed since it's supposed to be a string).