Last active
August 29, 2015 14:09
-
-
Save sim642/59eddbd3f2e730587e35 to your computer and use it in GitHub Desktop.
SFML utf8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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