+ 1
Why doesn't that work?
std::string Contostr(int num){ std::stringstream ss; ss << num; ss.str(); return num; } And is there any other ways to do so?
7 Antworten
+ 3
KarSah, i have already managed the problem:
std::string Contostr(int num){
std::string str;
std::stringstream ss;
ss << num;
ss >> str;
return str;
}
+ 1
I am not sure,but i think its becouse your function must return std::string but you are returning int
+ 1
KarSah, but doesn't num converts to string in this line:
ss.str(), as i added num here:
ss<<num;?
+ 1
Oleg Storm,i think no, cause num is another variable,if i understand correctly you need to return ss
+ 1
Anyway, thanks for your help🤗
+ 1
Oleg Storm,no problem😊,but you can make it without another string variable,simply returning ss.str()
std::string Contostr(int num){
std::stringstream ss;
ss << num;
return ss.str();
}
0
Oleg Storm , other option to achieve same is to_string...but prefer stringstream approach... might like to check below :
https://code.sololearn.com/c2l7g4m0zmas/?ref=app