我有問題在屏幕上打印文本。我雖然沒有有效的「+」運算符用於流出文本。這是爲什麼一個有效的:使用「<<」時「+」運算符的有效性
std::cout << ("print this number " + boost::lexical_cast<std::string>(5) + ". ") << std::endl;
雖然存在用於此complie錯誤:
std::cout << ("print this number " + "5" + ". ") << std::endl;
錯誤:類型的無效操作數 '爲const char [19]' 和 '爲const char [2]' 至二進制'運算符+'
我使用gcc 4.7.3和C++ 03。
如果使用字符串對象,則使用'+'運算符。請注意括號 – Hayt
'運算符+'用於'std :: string:'在此處使用。哪裏不對? – ilotXXI