如何在 boost::u32regex & reg 中打印值
How to print value in boost::u32regex & reg
我想使用std::cout
在boost::u32regex & reg
中打印一个值。
对于boost::regex & reg
,我可以打印reg.str()
,但不能使用str()
到boost::u32regex
。
有人能告诉我吗?
似乎boost::u32regex
后面使用的类型与cout
不兼容。他们似乎在使用ICU
库中的Uchar32
。
您可以使用迭代器打印regex值:
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>
#include <unicode/ustream.h>
void PrintRegex32( const boost::u32regex& r )
{
boost::u32regex::iterator it = r.begin();
boost::u32regex::iterator ite = r.end();
for ( ; it != ite; ++it )
{
std::cout << UnicodeString(*it) << std::endl;
}
}
这对我来说很有效。它不像打印boost::regex
值那么容易,但它很有效。我建议您创建一个函数来执行此操作,如示例中所示。
编辑:
你可以试试代码:
boost::u32regex r = boost::make_u32regex("(?:\A|.*\)([^\]+)");
PrintRegex32( r );
我可以打印
reg.str()
仅供参考,boost::basic_regex
有一个operator<<
过载,他们正在做完全相同的事情,所以:
// reg is a boost::regex
std::cout << reg.str() << std::endl;
和是一样的
// reg is a boost::regex
std::cout << reg << std::endl;
相关文章:
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 如何将结构插入到集合中并打印集合的成员
- 在循环C++中指定字符串之后,不会打印该字符串
- 以螺旋方式打印矩阵的程序.(工作不好)
- 从控制台中删除最后打印的元素
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何仅使用对象名称打印特定于对象的成员
- 回溯C++不打印函数,因此文件
- 在一定长度后从数组中打印时缺少整数
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 在gem5中打印文件中的所有cache_blocks
- 打印数字图案
- Log4cpp:以UTC/GMT时区打印日期
- 如何在 boost::u32regex & reg 中打印值