如何在c++; 我用SfML写C++游戏,我发现了一个支持法语字符的字体。然而,在这个程序中,我读取了文件中的所有文本,以便能够支持不同的语言,但我不知道如何将文本无误地提取到广泛的字符串中
这是我的密码:如何在c++; 我用SfML写C++游戏,我发现了一个支持法语字符的字体。然而,在这个程序中,我读取了文件中的所有文本,以便能够支持不同的语言,但我不知道如何将文本无误地提取到广泛的字符串中,c++,char,sfml,wchar,wifstream,C++,Char,Sfml,Wchar,Wifstream,这是我的密码: using namespace std; using namespace sf; void SettingsW :: initialize() { // using normal characters it reads the files correctly wifstream settTextFile; settTextFile.open(pageTextSource); wstring temp; getline(settTextFil
using namespace std;
using namespace sf;
void SettingsW :: initialize()
{
// using normal characters it reads the files correctly
wifstream settTextFile;
settTextFile.open(pageTextSource);
wstring temp;
getline(settTextFile, temp);
pageTitle.setFont(pageFont);
pageTitle.setString(temp);
getline(settTextFile, temp, L' ');
languageTitle.setFont(pageFont);
languageTitle.setString(temp);
//here is the problem
char g=' ';
ios::widen(g);
getline(settTextFile, temp, ' '));
// I want to use get line with this delimiter and when I use the L the error goes away
//but it doesn't display properly: é is displayed as ã
}
你的问题是什么还不太清楚。您当前的代码 不应该编译<代码>ios::加宽是一个成员函数,可以 只能在
ios
上调用(这是
std::basic_ios
,其中您的
代码)。另外,ios::加宽
返回加宽字符,除了
ios::加宽(与
std::basic(加宽)不会加宽,因为它返回
a
char。如果要使用
g中的字符,请使用分隔符
在对
std::getline`的最后一次调用中,您可以使用:
std::getline( settTextFile, tmp, settTextFile.widen( g ) );
(当然,您应该验证std::getline
是否成功
在使用它读取的值之前。)
关于“未正确显示”:
你必须提供更多关于你的情况的信息
为我们展示它是肯定的,但在我看来可能
您只是没有在输出流中注入相同的内容
编码为窗口的代码页(假定为窗口),或
使用窗口中使用的字体编码(假设
Unix)。但你必须让我们知道你到底在干什么
展示,你是如何展示的,给我们一些
如果需要完整答案,请提供有关环境的信息