Answer the question
In order to leave comments, you need to log in
How to correctly convert a file with utf-32 encoding to utf-8 using the UTF8-CPP library?
I have a file in utf-32 encoding and I need to convert it to utf-8, here is my program code:
#include "source/utf8.h"
using namespace std;
int main(int argc, char** argv)
{
const char* sourceFilePath = "/home/user/utf32.txt";
ifstream sourceFile(sourceFilePath, std::ifstream::binary);
ofstream outFile("/home/user/utf8result.txt");
vector<unsigned char> utf8result;
utf8::utf32to8(std::istreambuf_iterator<char>(sourceFile),
std::istreambuf_iterator<char>(),
back_inserter(utf8result));
outFile.write((char*)&utf8result[0], utf8result.size());
return 0;
}
Answer the question
In order to leave comments, you need to log in
utf8::utf32to8(std::istreambuf_iterator<char32_t>(sourceFile),
std::istreambuf_iterator<char32_t>(),
back_inserter(utf8result));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question