1
Graphics / Wide string literal from string stored in variable
« on: August 12, 2019, 01:20:47 am »
Im having trouble with some accented European characters (åäö). I have read the documentation, and I know that you are supposed to use a wide literal for SFML to be able to display these characters.
The font I am using has these characters, as I can create a sf::Text with the European characters. Say I have the following code snippets:
This one works as expected:
which draws 'åäö'.
But I have no idea how to draw a string containing "åäö" from a string variable? I tried to do this:
I also tried this
but that does not work either. Any ideas?
The font I am using has these characters, as I can create a sf::Text with the European characters. Say I have the following code snippets:
This one works as expected:
sf::Text t;
t.setString(L"åäö");
t.setFont(...);
window.draw(t);
t.setString(L"åäö");
t.setFont(...);
window.draw(t);
which draws 'åäö'.
But I have no idea how to draw a string containing "åäö" from a string variable? I tried to do this:
std::string temp = "åäö";
sf::String s(temp);
sf::Text t;
t.setString(s.toWideString());
font, draw, etc...
sf::String s(temp);
sf::Text t;
t.setString(s.toWideString());
font, draw, etc...
I also tried this
std::string narrow_string("åäö");
std::wstring wide_string = std::wstring(narrow_string.begin(), narrow_string.end());
const wchar_t* result = wide_string.c_str();
sf::Text t;
t.setString(result);
font, draw, etc...
std::wstring wide_string = std::wstring(narrow_string.begin(), narrow_string.end());
const wchar_t* result = wide_string.c_str();
sf::Text t;
t.setString(result);
font, draw, etc...
but that does not work either. Any ideas?