Lemmons
Lemmons

Reputation: 1806

SFML add to sf::String?

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"

Upvotes: 2

Views: 3582

Answers (2)

asdfjklqwer
asdfjklqwer

Reputation: 3594

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.

Upvotes: 5

user418748
user418748

Reputation:

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

Upvotes: 3

Related Questions