# Does anyone know why this does not work?

## Recommended Posts

kappa    138
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? #### Share this post ##### Link to post ##### Share on other sites MetaCipher 145 char Buffer[255]; sprintf(Buffer, "%d", 500); Use %f for floating point numbers. #### Share this post ##### Link to post ##### Share on other sites moagstar 263 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 #### Share this post ##### Link to post ##### Share on other sites kappa 138 .net 2002 wierd... #### Share this post ##### Link to post ##### Share on other sites moagstar 263 Have you made sure your including the correct files, you need #include <string> #include <sstream> That might cause that prob #### Share this post ##### Link to post ##### Share on other sites kappa 138 I have them both included, downloaded the 2003 toolkit and see if it works with that. #### Share this post ##### Link to post ##### Share on other sites moagstar 263 Yeah I am using 2003 toolkit, so hopefully it should work 4 u #### Share this post ##### Link to post ##### Share on other sites Guest Anonymous Poster 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 ?

##### Share on other sites
kappa    138

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.

##### Share on other sites
Cygon    1219
Did you examine this line:
Quote:
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-

##### Share on other sites
kappa    138
Yeah I did, and I had no idea why it was complaining about that.

1. no, I am not using any STL replacment libraries
2. well now I do :P, I didn't before this.

##### Share on other sites
Fruny    1658
Well, one (obvious? [grin]) way to fix that would be to dig in and hack your standard library headers (the implementation is all in there). [wink]

##### Share on other sites
kappa    138
Sure if I could find where the error originates from, justy heading to the ostreambuf_iterator does not help me much.