GCC, std::ctype specialisation & streams
GCC, std::ctype specialisation & streams
我已经为std::ctype<char16_t>
的每个虚拟成员函数编写了自己的专业化,因此现在可以使用:
#include <string>
#include <locale>
#include "char16_facets.h" // Header containing my ctype specialisation
#include <sstream>
#include <iostream>
// Implemented elsewhere using iconv
std::string Convert(std::basic_string<char16_t>);
int main() {
std::basic_string<char16_t> s("Hello, world.");
std::basic_stringstream<char16_t> ss(s);
ss.imbue(std::locale(ss.getloc(), new std::ctype<char16_t>()));
std::basic_string<char16_t> t;
ss >> t;
std::cout << Convert(t) << " ";
ss >> t;
std::cout << Convert(t) << std::endl;
}
有没有一种方法可以让流在默认情况下使用新的ctype专业化,这样我就不必为每个流imbue
指定一个新的区域设置?
我还没有写新的课,只是提供了
template<>
inline bool std::ctype<char16_t>::do_is (std::ctype_base::mask m, char16_t c) const {
等等。我有点希望它会自动被提取,只要它是在我#include <sstream>
之前声明的,但它不是。
上面的大部分工作都是使用G++和libstdc++4.8完成的,但我使用从SVN主干构建的它们得到了相同的结果。
编辑-更新这个问题最初是关于如何进行数字提取的。然而,给定一个充满正确ctype
和numpunct
实现的流,则不需要对num_get
进行专门化;简单
ss.imbue(std::locale(ss.getloc(), new std::num_get<char16_t>()));
它将工作,与任何一个gcc版本。
同样,有没有什么方法可以让流自动收集这些信息,而不是让每条流都充满这些信息?
使用std::locale::global()
:
std::locale::global(std::locale(std::locale(), new std::ctype<char16_t>()));
相关文章:
- 面临分段故障 使用 ffmpeg 读取视频时,因为"pFormatCtx-> streams [i]-> codecpar"的地址0x00
- 如何创建一个 while 循环,继续循环,直到在C++中输入'using streams'键?
- C++应用程序缺少 winrt::Windows::Storage::Streams::D ataWriter
- 用于测试目的:"special"哪些浮点数(IEEE754 32b)?
- C++抛出错误"Invalid special open parenthesis."中的正则表达式
- Qt5 QProcess 处理具有"special"字符的参数
- Introduction To C++ IO Streams
- 为什么cpplint不鼓励Streams
- Streams中的内联忽略
- 在C++std::streams中,失败后,如何获得失败原因?必需:线程安全,适用于Windows和Linux(或至少M
- 从 Windows::Storage::Streams::IBuffer 中获取字节数组
- GCC, std::ctype specialisation & streams
- 尝试在C++中制作 ASCII 表,无法使"special characters"正确显示
- cstdio streams vs iostream streams?
- C++ io streams versus mmap
- C++11 File Streams
- 是否可以防止此代码"copy and paste similar template special case"?
- c++ JNI在做任何IO/Streams时崩溃/挂起
- boost::streams::output过滤器的意外行为
- Including windows.storage.streams.h