我正在使用 Vstual Studio 2022 并使用 c++ 14
if (vm.count("include-path"))
{
cout << "Include paths are: "
<< vm["include-path"].as< vector<string> >() << "\n";
}
我第二个有错误<< operator. The error says thats there is no "<<" operator matching the operands.
自从我一步步遵循 boost_program_options 教程以来,我就没有什么可以尝试的了。
编辑: 我尝试自己“解决”定义运算符的问题:
template <class T>
ostream& operator <<(ostream& os, const vector<T>& v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it)
os << *it << " ";
os << "]";
return os;
}
回复:
我尝试自己“解决”定义运算符的问题:
它需要在通过参数依赖查找关联的命名空间中定义:https://en.cppreference.com/w/cpp/language/adl
在这种情况下,您不能拥有除
std
之外的其他命名空间,因为它声明了 std::vector
和 std::string
(并且 std::char_traits<char>
和 std::allocator
是完整的)。