I’m having a bit of a problem with this piece of code:
string StringServices::ToStringf(float value)
{
char buffer[10];
sprintf (buffer, "%f", value);
return (string) buffer; // signal SIGABRT
}
Its been working previously and continues to work for other calls, but I currently get a SIGABRT on the return, when the function is being passed -211.0
The buffer loads up fine, and I’m really not sure why this isn’t working. Can someone who understands std::string and c strings a lot better then me help me out here?
You probably overflowed your buffer because you’re not using
snprintf. You have this tagged C++ so do it that way:std::string buffer = boost::lexical_cast<std::string>(value);Or without boost use a string stream: