#### Archived

This topic is now archived and is closed to further replies.

# extra numbers appearing....

## Recommended Posts

ok, so Im trying to convert stings to ints.... Im using the strings found in and a couple of functions I built after reading some things off another site. The problem as the title suggests, is that Im getting extra numbers on the end. I thought it might be garbage, but it is always the same.... if I want to convert 15 I''ll get 150040105F.... weird.. anyway the first function is as follows:

string intToString(int x) {

ostringstream stream;
string temp;
stream << x << ends;
return(temp = stream.str());

}// end intToString()


and the second:

template<class T>
string ToString(const T& source)
{
ostringstream oss;
oss << source;
return oss.str();
};

now the second did work if I had it declared in the same file as it was being used, but if it was put in a header and included then it added the numbers.... Im utterly confused by this... any ideas????

##### Share on other sites
The ends is unnecessary, as indeed is the temp variable. Just return stream.str(). Not sure about the extra numbers. Are you doing a full rebuild? What compiler and STL library are you using?

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

##### Share on other sites
good points both of them....

Im using VC++ 6.0 with all of the normal libs, so I guess their STL libs.... Im none to up to it with STL... anyway, Im re-buildin everything each time... ::shrug:: I have a hack in place that just removes the numbers off the end, but that could do a lot of damage so Im trying to find a way around it...

• ### Forum Statistics

• Total Topics
628362
• Total Posts
2982266

• 10
• 9
• 13
• 24
• 11