0

我最近遇到类似这样的代码:

std::string myString = "test";
boost::format fmt("%s");

fmt % myString;

(第二个) % 运算符在这里做什么?

编辑:

我了解最终结果,但我找不到如何像这样使用 % 运算符的定义。

有人可以提供一个示例来解释 % 运算符的确切含义吗?

4

2 回答 2

3

我了解最终结果,但我找不到如何像这样使用 % 运算符的定义。

operator %可以超载。Boost.Format 正是为它的basic_format做的:

template<class T>  
basic_format&   operator%(const T& x)
    { return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); }

每当您使用fmt % valuewhere fmtis 类型的代码时,都会调用此成员函数boost::basic_format<Ch>

于 2013-05-21T23:40:03.047 回答
1

%是一个重载的运算符。 点击这里。

于 2013-05-21T23:39:59.530 回答