【问题标题】:How to use russian text in SFML?如何在 SFML 中使用俄语文本?
【发布时间】:2020-02-26 17:15:01
【问题描述】:

我正在尝试在我的 SFML 应用程序中打印俄语文本,但我只收到奇怪的符号。我知道,我可以做到:

text.setString(L"blabla")

但是,我想从文件中获取文本。我在我的项目中使用 Unicode。 截图:

【问题讨论】:

  • 您确定您使用的字体适合西里尔文吗?似乎使用正确的字体可以解决这个问题。

标签: c++ unicode sfml cyrillic


【解决方案1】:

为了兼容性和简单性,您可以使用 UTF8 来存储文件。读取文件,然后转换 UTF8 字符串。如果您将文件保存在记事本等中,请确保它以 UTF8 格式保存。如果使用 UTF16 文件,您将遇到额外的复杂情况。 ANSI 格式已过时,不推荐使用。

#include <fstream>
#include <string>
#include <sstream>
...

std::ofstream fout(L"file.txt"); //Visual Studio allows wide char file name here
fout << u8"Test ελληνικά...";
fout.close();

std::ifstream fin(L"file.txt");
std::stringstream ss;
ss << fin.rdbuf();
std::string utf8 = ss.str();
sf::String str = sf::String::fromUtf8(utf8.begin(), utf8.end());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2013-08-03
    • 2010-10-23
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    相关资源
    最近更新 更多