hi guys i wanna put an intiger into a string for example:
i ve seen some examples but ive not yet come up with a solutionCode:string name; int num=8; name= "George" //i want in the end of George to pas the num variable
like str.insert();
hi guys i wanna put an intiger into a string for example:
i ve seen some examples but ive not yet come up with a solutionCode:string name; int num=8; name= "George" //i want in the end of George to pas the num variable
like str.insert();
Have you seen example usage of a stringstream?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
xmm not really i will do search now
thanks find out the solutionCode:int main () { int num=4; std::stringstream ss; ss.str ("George_"); std::string s = ss.str(); std::cout << s << num<<endl; system("pause"); return 0; }
but how can i pass this resualt to a string for example:
Code:int main () { int num=4; stringstream ss; ss.str ("George_"); string s = ss.str(); string n = s << num; system("pause"); return 0; }
You've almost got it. Take a look how you can use stringstream.
Code:int main() { string name = "George"; int num = 4; stringstream ss; ss << name << "_" << num; string result = ss.str(); cout << result << '\n'; system("pause"); return 0; }
ooo yea now i see thenx very much