Question

So I've been using SFML lately and I was wondering how I could "add" to sf::String.

For example:

sf::String exampleText;
exampleText.SetText("I say: ");
exampleText += "Blah";

Result: "I say: Blah"

Was it helpful?

Solution

sf::string doesn't offer an append method which makes sense as it's intended to be a class for the graphical display of text rather than a traditional string class.

So you have to perform your string manipulation/append operations behind the scenes using your usual char array/string/stringstream classes and then call sf::string::SetText to update it.

OTHER TIPS

sf::String exampleText;
exampleText.SetText("I say: ");
std::wstring toAppend(L"Blah");
exampleText.SetText(exampleText.GetUnicodeText() + toAppend);

Try that. I have never used sf though.

GetUnicodeText returns std::wstring. And by using the + it may work. Try it.

OR (now that I saw the sf docs better)

exampleText.SetText(exampleText.GetText() + "Blah");

GetText() returns std::string SetText() Accepts both wstring and string

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top