所以我最近一直在使用SFML,我想知道如何“添加”到sf :: String。
例如:
sf::String exampleText;
exampleText.SetText("I say: ");
exampleText += "Blah";
结果:“我说:Blah”
答案 0 :(得分:5)
sf :: string不提供有意义的append方法,因为它旨在成为文本图形显示的类而不是传统的字符串类。
所以你必须使用常用的char数组/字符串/字符串流类在幕后执行字符串操作/追加操作,然后调用sf :: string :: SetText来更新它。
答案 1 :(得分:3)
sf::String exampleText;
exampleText.SetText("I say: ");
std::wstring toAppend(L"Blah");
exampleText.SetText(exampleText.GetUnicodeText() + toAppend);
试试吧。我从未使用过sf
。
GetUnicodeText
返回std::wstring
。通过使用+
它可能会起作用。试试吧。
或(现在我看到了sf文档更好)
exampleText.SetText(exampleText.GetText() + "Blah");
GetText()
返回std :: string
SetText()
接受wstring
和string