Skip to content

Instantly share code, notes, and snippets.

@sim642
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sim642/59eddbd3f2e730587e35 to your computer and use it in GitHub Desktop.
Save sim642/59eddbd3f2e730587e35 to your computer and use it in GitHub Desktop.
SFML utf8
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include <SFML/System/String.hpp>
#include <SFML/System/Utf.hpp>
using namespace std;
sf::String fromUtf8(const string &in)
{
basic_string<sf::Uint32> tmp;
sf::Utf8::toUtf32(in.begin(), in.end(), back_inserter(tmp));
return sf::String(tmp);
}
string toUtf8(const sf::String &str)
{
string out;
sf::Utf32::toUtf8(str.begin(), str.end(), back_inserter(out));
return out;
}
int main()
{
ifstream fin("in.txt");
string in;
getline(fin, in);
cout << in.size() << endl;
sf::String str = fromUtf8(in);
cout << str.getSize() << endl;
string out = toUtf8(str);
cout << out.size() << endl;
ofstream fout("out.txt");
fout << out << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment