<small id='fTwJa'></small><noframes id='fTwJa'>

      <tfoot id='fTwJa'></tfoot>
    1. <legend id='fTwJa'><style id='fTwJa'><dir id='fTwJa'><q id='fTwJa'></q></dir></style></legend>

        <bdo id='fTwJa'></bdo><ul id='fTwJa'></ul>

      1. <i id='fTwJa'><tr id='fTwJa'><dt id='fTwJa'><q id='fTwJa'><span id='fTwJa'><b id='fTwJa'><form id='fTwJa'><ins id='fTwJa'></ins><ul id='fTwJa'></ul><sub id='fTwJa'></sub></form><legend id='fTwJa'></legend><bdo id='fTwJa'><pre id='fTwJa'><center id='fTwJa'></center></pre></bdo></b><th id='fTwJa'></th></span></q></dt></tr></i><div id='fTwJa'><tfoot id='fTwJa'></tfoot><dl id='fTwJa'><fieldset id='fTwJa'></fieldset></dl></div>

        如何在vc++中读取包含uxxxx的文件

        How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
      2. <i id='PV1P2'><tr id='PV1P2'><dt id='PV1P2'><q id='PV1P2'><span id='PV1P2'><b id='PV1P2'><form id='PV1P2'><ins id='PV1P2'></ins><ul id='PV1P2'></ul><sub id='PV1P2'></sub></form><legend id='PV1P2'></legend><bdo id='PV1P2'><pre id='PV1P2'><center id='PV1P2'></center></pre></bdo></b><th id='PV1P2'></th></span></q></dt></tr></i><div id='PV1P2'><tfoot id='PV1P2'></tfoot><dl id='PV1P2'><fieldset id='PV1P2'></fieldset></dl></div>
      3. <legend id='PV1P2'><style id='PV1P2'><dir id='PV1P2'><q id='PV1P2'></q></dir></style></legend>

          <bdo id='PV1P2'></bdo><ul id='PV1P2'></ul>
          <tfoot id='PV1P2'></tfoot>

            <small id='PV1P2'></small><noframes id='PV1P2'>

                  <tbody id='PV1P2'></tbody>
                • 本文介绍了如何在vc++中读取包含uxxxx的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个txt文件,其内容是:

                  I have txt file whose contents are:

                  u041fu0435u0440u0432u044bu0439_u0438u043du0442u0435u0440u0430u043au0442u0438u04u04u043u04u04u043u04u043u043u04u04304u0440u043du0435u0442_u043au0430u043du0430u043b

                  u041fu0435u0440u0432u044bu0439_u0438u043du0442u0435u0440u0430u043au0442u0438u0432u043du044bu0439_u0438u043du0442u0435u0440u043du0435u0442_u043au0430u043du0430u043b

                  我怎样才能读取这样的文件来得到这样的结果:

                  How can I read such file to get result like this:

                  Первый_интерактивный_интернет_канал"

                  "Первый_интерактивный_интернет_канал"

                  如果我输入:

                  string str = _T("u041fu0435u0440u0432u044bu0439_u0438u043du0442u0435u0440u0430u043au0442u0438u0432u043du044bu0439_u0438u043du0442u0435u0440u043du0435u0442_u043au0430u043du0430u043b");
                  

                  然后结果 str 很好,但是如果我从文件中读取它,那么它与文件中的结果相同.我想这是因为 'u' 变成了 'u'.有没有简单的方法将 uxxxx 符号转换为 C++ 中的相应符号?

                  then result in str is good but if I read it from file then it is the same like in file. I guess it is because 'u' becomes 'u'. Is there simple way to convert uxxxx notation to corresponding symbols in C++?

                  推荐答案

                  以下是 MSalters 建议的示例:

                  Here is an example for MSalters's suggestion:

                  #include <iostream>
                  #include <string>
                  #include <fstream>
                  #include <algorithm>
                  #include <sstream>
                  #include <iomanip>
                  #include <locale>
                  
                  #include <boost/scoped_array.hpp>
                  #include <boost/regex.hpp>
                  #include <boost/numeric/conversion/cast.hpp>
                  
                  std::wstring convert_unicode_escape_sequences(const std::string& source) {
                    const boost::regex regex("\\u([0-9A-Fa-f]{4})");  // NB: no support for non-BMP characters
                    boost::scoped_array<wchar_t> buffer(new wchar_t[source.size()]);
                    wchar_t* const output_begin = buffer.get();
                    wchar_t* output_iter = output_begin;
                    std::string::const_iterator last_match = source.begin();
                    for (boost::sregex_iterator input_iter(source.begin(), source.end(), regex), input_end; input_iter != input_end; ++input_iter) {
                      const boost::smatch& match = *input_iter;
                      output_iter = std::copy(match.prefix().first, match.prefix().second, output_iter);
                      std::stringstream stream;
                      stream << std::hex << match[1].str() << std::ends;
                      unsigned int value;
                      stream >> value;
                      *output_iter++ = boost::numeric_cast<wchar_t>(value);
                      last_match = match[0].second;
                    }
                    output_iter = std::copy(last_match, source.end(), output_iter);
                    return std::wstring(output_begin, output_iter);
                  }
                  
                  int wmain() {
                    std::locale::global(std::locale(""));
                    const std::wstring filename = L"test.txt";
                    std::ifstream stream(filename.c_str(), std::ios::in | std::ios::binary);
                    stream.seekg(0, std::ios::end);
                    const std::ifstream::streampos size = stream.tellg();
                    stream.seekg(0);
                    boost::scoped_array<char> buffer(new char[size]);
                    stream.read(buffer.get(), size);
                    const std::string source(buffer.get(), size);
                    const std::wstring result = convert_unicode_escape_sequences(source);
                    std::wcout << result << std::endl;
                  }
                  

                  我总是惊讶于 C++ 中看似简单的事情是多么复杂.

                  I'm always surprised how complicated seemingly simple things like this are in C++.

                  这篇关于如何在vc++中读取包含uxxxx的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                  std::unordered_map very high memory usage(std::unordered_map 非常高的内存使用率)
                  <tfoot id='rEc3j'></tfoot>
                  • <bdo id='rEc3j'></bdo><ul id='rEc3j'></ul>

                    <small id='rEc3j'></small><noframes id='rEc3j'>

                        <tbody id='rEc3j'></tbody>
                      • <i id='rEc3j'><tr id='rEc3j'><dt id='rEc3j'><q id='rEc3j'><span id='rEc3j'><b id='rEc3j'><form id='rEc3j'><ins id='rEc3j'></ins><ul id='rEc3j'></ul><sub id='rEc3j'></sub></form><legend id='rEc3j'></legend><bdo id='rEc3j'><pre id='rEc3j'><center id='rEc3j'></center></pre></bdo></b><th id='rEc3j'></th></span></q></dt></tr></i><div id='rEc3j'><tfoot id='rEc3j'></tfoot><dl id='rEc3j'><fieldset id='rEc3j'></fieldset></dl></div>
                      • <legend id='rEc3j'><style id='rEc3j'><dir id='rEc3j'><q id='rEc3j'></q></dir></style></legend>