Does anyone know why this does not work?

Started by
11 comments, last by kappa 19 years ago

template<class T>
std::string cast_num( T nmbr )
{
	std::ostringstream s;
	if( s << nmbr )
		return s.str();
	return "\0";
}
I want to convert any number to a string, I found this and it looked like it would work. But when I run it I get the following error: hl error LNK2019: unresolved external symbol _use_Q_snprintf_instead_of_sprintf referenced in function "protected: virtual class std::ostreambuf_iterator<char,struct std::char_traits<char> > __thiscall std::num_put<char,class std::ostreambuf_iterator<char,struct std::char_traits<char> > >::do_put(class std::ostreambuf_iterator<char,struct std::char_traits<char> >,class std::ios_base &,char,long)const " (?do_put@?$num_put@DV?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@MBE?AV?$ostreambuf_iterator@DU?$char_traits@D@std@@@2@V32@AAVios_base@2@DJ@Z) Anyone know anyother way I can do this? and why this does not work?
Advertisement

char Buffer[255];
sprintf(Buffer, "%d", 500);

Use %f for floating point numbers.
It works fine with my compiler, which compiler are you using, if you are using vc++ 6.0 then it could be your compiler and time to update :D
.net 2002 wierd...
Have you made sure your including the correct files, you need

#include <string>
#include <sstream>

That might cause that prob
I have them both included, downloaded the 2003 toolkit and see if it works with that.
Yeah I am using 2003 toolkit, so hopefully it should work 4 u
Quote:Original post by kappa
*** Source Snippet Removed ***

I want to convert any number to a string, I found this and it looked like it would work. But when I run it I get the following error:

hl error LNK2019: unresolved external symbol _use_Q_snprintf_instead_of_sprintf referenced in function "protected: virtual class std::ostreambuf_iterator > __thiscall std::num_put >::do_put(class std::ostreambuf_iterator >,class std::ios_base &,char,long)const " (?do_put@?$num_put@DV?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@MBE?AV?$ostreambuf_iterator@DU?$char_traits@D@std@@@2@V32@AAVios_base@2@DJ@Z)

Anyone know anyother way I can do this? and why this does not work?


Another way: You shouldn't bother. This is legit code.
Doesn't work: Becuz your C++ standard library is broken. Which compiler are you using ?
read the thread :P

I use .net 2002, does anyone know how to use the 2002 IDE for the 2003 toolkit? I can't find any of the websites telling me how right now.
Did you examine this line:
Quote:unresolved external symbol _use_Q_snprintf_instead_of_sprintf
Obviously, your stringstream implementation internally uses sprintf() to perform the conversion, which is something your runtime library doesn't want you to.

You probably have your runtime library components mixed up between two different versions, products or vendors.
- Are you, by any chance, using STLport in VS.NET 2002 or some other STL replacement library ?
- Do you have other C++ compilers (including older/newer versions of VisualStudio) installed on this system ? (your include paths might incorporate the other compiler's directories)

-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.

This topic is closed to new replies.

Advertisement