This helped me a lot, and it could be useful to someone. I've adapted the solution proposed on another forum post (
here's a link).
Here's the solution I used:
// Takes sf::String (UTF-32) and returns std::string (UTF-8)
std::string to_std_string(const sf::String& original)
{
// The final UTF-8 string
std::string str;
// Worst case scenario: 4 bytes per codepoint
str.resize(original.getSize() * 4);
std::string::iterator last = sf::Utf<32>::toUtf8( original.getData(),
original.getData() + original.getSize(), str.begin() );
str.resize(last - str.begin());
return str;
}
This will take any sf::String containing unicode codepoint and pass it to a std::string that can be used to output to anywhere. You can even use this std::string for filenames.
NOTE: I've tested this with the main Linux distros (Debian, OpenSUSE, Arch, Fedora, etc.) and Windows XP/Vista/7. The behavior appears to be consistent, but it may not be that way for all machines.
You can set a unicode character by using its codepoint:
// Codepoint in decimal
sf::Uint32 unicode_char = 12354;
// Append unicode char to an sf::String
sf::String unicode_string += unicode_char;
This will create the character '0x3042' (or '12354' in decimal) which is the hiragana character 'あ'. For reference,
here's a list of unicode characters along with their codepoint.