Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么std::codecvt仅由文件I/O流使用?_C++_File_Facet_Ostream_Codecvt - Fatal编程技术网

C++ 为什么std::codecvt仅由文件I/O流使用?

C++ 为什么std::codecvt仅由文件I/O流使用?,c++,file,facet,ostream,codecvt,C++,File,Facet,Ostream,Codecvt,我一直在实现一个codevt来处理输出流的标识。它可以像这样使用,并且工作良好: std::cout << indenter::push << "im indentet" << indenter::pop << "\n im not..." 在std::ostringstream中进行流式处理后,我会增加invocation\u计数器,但它没有 更新2: 经过更多的研究,我发现我可以使用std::wbuf

我一直在实现一个codevt来处理输出流的标识。它可以像这样使用,并且工作良好:

std::cout << indenter::push << "im indentet" << indenter::pop << "\n im not..."
std::ostringstream
中进行流式处理后,我会增加
invocation\u计数器
,但它没有


更新2: 经过更多的研究,我发现我可以使用
std::wbuffer\u转换器
。引用

std::wbuffer\u convert
是类型为的流缓冲区上的包装器
std::basic_streambuf
它的外观是
std::basic\u streambuf
。所有I/O都是通过
std::wbuffer\u convert
按照 面编解码器。[……]

该类模板进行隐式字符转换
std::basic_filebuf
的功能可用于任何
std::basic\u streambuf

通过这种方式,我可以将方面应用于
std::ostringstream

auto osstream = std::ostringstream {};

osstream << "test\n";
  
auto facet = custom_facet{};
  
std::wstring_convert<custom_facet, char> conv;
  
auto str = conv.to_bytes(osstream.str());
auto-osstream=std::ostringstream{};

osstream我不知道这方面的把戏,但也许只是使用
std::format
,而完全忘记iostream?@passer我曾想过使用
std::format
,但使用streams的优点是,它可以使用它得到的任何流。我在json序列化程序中使用了压头,它能够使用从
std::ostream
派生的对象引用写入任何输出流。这样我就可以序列化成
std::ofstream
,一个
std::ostringstream
,或者
std::cout
。使用
std::format
我将失去这种灵活性,因为序列化程序是递归调用每个对象成员进行序列化的。C++98的std::codevt没有被弃用,只有从中派生的C++11的Unicode转换区域设置被弃用。
auto osstream = std::ostringstream {};

osstream << "test\n";
  
auto facet = custom_facet{};
  
std::wstring_convert<custom_facet, char> conv;
  
auto str = conv.to_bytes(osstream.str());