Re: INT to STR
From: keanu (usenet_at_keanu.be)
Date: 11/05/03
- Next message: zhouhaiming: "I can't execute my program(coded by c language) on AIX5.2(ML2)"
- Previous message: Marcel: "INT to STR"
- In reply to: Marcel: "INT to STR"
- Next in thread: Marcel: "Re: INT to STR"
- Reply: Marcel: "Re: INT to STR"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 05 Nov 2003 11:06:38 GMT
Marcel wrote in <3fa8d7f0$0$9476$edd6591c@news.versatel.net>:
> The small code underneath is displaying the text 'hello2' as output. I
> supposed it to display hello50. I think i will have to convert the int to
> a string or am i wrong? If so, what is the right command? Sorry i am a
> beginner....
>
> Thanks in advance!
>
> #include <iostream>
> #include <string>
#include <sstream>
template<typename T> std::string toStr(T var) {
std::ostringstream tmp; tmp << var; return tmp.str();
}
> int main() {
> int red = 50;
> std::string temp = "";
> temp += "hello";
//temp += red;
temp += toStr<int>(red);
> std::cout << temp;
> std::cin.get();
> return 0;
> }
- Next message: zhouhaiming: "I can't execute my program(coded by c language) on AIX5.2(ML2)"
- Previous message: Marcel: "INT to STR"
- In reply to: Marcel: "INT to STR"
- Next in thread: Marcel: "Re: INT to STR"
- Reply: Marcel: "Re: INT to STR"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|