【问题标题】:SFML add to sf::String?SFML 添加到 sf::String?
【发布时间】:2011-01-01 00:24:50
【问题描述】:

所以我最近一直在使用 SFML,我想知道如何“添加”到 sf::String。

例如:

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

结果:“我说:废话”

【问题讨论】:

    标签: c++ sfml


    【解决方案1】:

    sf::string 没有提供有意义的 append 方法,因为它旨在成为文本图形显示的类,而不是传统的字符串类。

    因此,您必须使用常用的字符数组/字符串/字符串流类在幕后执行字符串操作/追加操作,然后调用 sf::string::SetText 对其进行更新。

    【讨论】:

    • headdesk 人们告诉我我需要更多的睡眠。我应该开始听他们的。谢谢。
    • 没问题,我知道这种感觉:D
    【解决方案2】:
    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() 接受 wstringstring

    【讨论】:

    • -1 因为 GetUnicodeText() (显然)不是 sf::String 的成员。 ;)
    猜你喜欢
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 2016-04-23
    相关资源
    最近更新 更多