SFML 添加到 sf::String?
所以我最近一直在使用 SFML,我想知道如何“添加”到 sf::String。
例如:
sf::String exampleText;
exampleText.SetText("I say: ");
exampleText += "Blah";
结果:“我说:Blah”
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
sf::string 不提供有意义的追加方法,因为它旨在成为用于图形显示文本的类,而不是传统的字符串类。
因此,您必须使用常用的 char 数组/字符串/stringstream 类在幕后执行字符串操作/附加操作,然后调用 sf::string::SetText 来更新它。
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.
尝试一下。不过我从未使用过 sf 。
GetUnicodeText
返回std::wstring
。通过使用+
它可能会起作用。尝试一下。或者(现在我更好地看到了 sf 文档)
exampleText.SetText(exampleText.GetText() + "Blah");
GetText()
返回 std::stringSetText()
接受wstring
和string
Try that. I have never used
sf
though.GetUnicodeText
returnsstd::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::stringSetText()
Accepts bothwstring
andstring