convert int or float to char

hi I am using SDL and TTF_RenderText_Solid() to show text in my game.
I have an int variable and a float variable that I need to be able to write into my string of text in the TTF_RenderText_Solid() function. If I try to directly put an int there to write it will give me an error about not being able to convert to a const char*

I tried (char*)myIntVar and the program ran but crashed when it hit that line. I tried including <string> and doing it that way but it wants a char*

thanks for any help!
The problem could be (without seeing code) that the int/float could be out of range for the supported char it is trying to convert to. We would have to see the code to be able to say for sure one way or the other as to what is going on in the code because it may be crashing there, but the problem could be elsewhere in your code and it is only catching there.
i have an int and I have no idea how to convert it, all I have tried is what I said, literally writing (char*) infront of the int.
C++11: std::to_string() http://en.cppreference.com/w/cpp/string/basic_string/to_string

C++98: boost::lexical_cast http://www.boost.org/doc/libs/1_49_0/doc/html/boost_lexical_cast.html
or something like this
1
2
3
4
5
6
7
template < typename T > std::string to_string( const T& v, int precision = 2 )
{
    std::ostringstream stm ;
    stm << std::fixed << std::setprecision(precision) << std::boolalpha ;
    stm << v ;
    return stm ? stm.str() : "*** error ***" ;
}
is there a problem with the way I am doing this?
1
2
3
4
5
6
Game::showHUD(int playerMoney) {
    stringstream playerCash;
    playerCash << "Cash ";
    playerCash << playerMoney;
    p_HUDmoney = TTF_RenderText_Solid(resultFont, playerCash.str().c_str(), winColor );
}


the game runs but if I run the debugger I get an error and on the watches panel it says playerCash = <incomplete type>
> I get an error and on the watches panel it says playerCash = <incomplete type>

Do you have a #include <sstream> ?
Topic archived. No new replies allowed.