如何使用std修复错误:ifstreambuf_iterator <char32_t>?

时间:2018-02-25 10:56:06

标签: c++ utf-8 character-encoding utf-32

我有这个简单的代码,它必须从文件中迭代四个字节并将其传递给函数utf8 :: utf32to8,它将文件从utf32编码转换为utf8:

ifstream my_file(sourceFilePath, std::ifstream::binary);

vector<unsigned char> res_utf8;
utf8::utf32to8(std::istreambuf_iterator<char32_t>(my_file),
               std::istreambuf_iterator<char32_t>(),
               back_inserter(res_utf8));
out.write((char*)&res_utf8[0], res_utf8.size());

但是当我编译时,我得到了这个错误:

error: invalid user-defined conversion from 'std::ifstream {aka std::basic_ifstream<char>}' to 'std::istreambuf_iterator<char32_t>::streambuf_type* {aka std::basic_streambuf<char32_t, std::char_traits<char32_t> >*}' [-fpermissive]
         utf8::utf32to8(std::istreambuf_iterator<char32_t>(my_file),
                                                                  ^

请帮助我成功编译此代码。

0 个答案:

没有答案