gpt4 book ai didi

c++ - 如何在SFML中使用俄语文本?

转载 作者:行者123 更新时间:2023-12-02 10:05:27 25 4
gpt4 key购买 nike

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

text.setString(L"blabla")

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

Screenshot

最佳答案

为了兼容和简单起见,您可以使用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());

关于c++ - 如何在SFML中使用俄语文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60419161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com