Sign in to follow this  

SDL TTF- strings ?

Recommended Posts

I'm trying to make SDL display a string type but aparently SDL TTF only supports C Strings or static strings. here's the line that's causing me the trouble: line1 = TTF_RenderText_Solid( font, currentline1, textColor ); the error says the compiler can't convert a std:string to a const char*, which I suppose means the TTF_RenderText_Solid function only supports C Strings or static strings but no C++ strings ("currentline1"). Is there any way around this ?

Share this post

Link to post
Share on other sites
Original post by Kingerthethird
This is the solution I use:

std::string strMessage = "Hello World!";
SDL_Surface* surText;
surText = TTF_RenderText_Solid( ttfFont, &strMessage[0], colWhite );

Please use strMessage.c_str() and don't access the std::string internal buffer directly unless you have to as it defeats the purpose of using a std::string vs a standard character array.

surText = TTF_RenderText_Solid( ttfFont, strMessage.c_str(), colWhite );

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this