【发布时间】:2017-12-17 10:15:08
【问题描述】:
main.cpp: In function ‘void PrintVector(std::vector<std::__cxx11::basic_string<char> >&, bool)’:
main.cpp:16:41: error: overloaded function with no contextual type information
std::cout << ((newline)? (std::endl) : "");
^~
为什么 std::cout 不喜欢条件 if 中的 std::endl 和字符串?
【问题讨论】:
-
请分享您的代码
-
三元运算符需要相同类型的结果值。
-
这里也没有性能原因使用三元运算符。
?:和 if-else-statement 之间的差异(如果有)将被 I/O 操作的成本所掩盖。 -
这不是问题,但您不需要在
newline和std::endl周围加上括号。
标签: c++ conditional cout stdstring