尝试编译以下函数时出现以下错误:
Error: invalid operands of types int and const char [3] to binary operator
我该如何解决这个问题?
string getFormattedDate()
{
formattedDate = Date.getDay() << "/" << Date.getMonth() << "/" << Date.getYear();
return formattedDate;
}
答案 0 :(得分:8)
你不能这样做,它不是有效的C ++。也许你想要:
#include <sstream>
// ...
string getFormattedDate()
{
std::ostringstream ss;
ss << Date.getDay() << "/" << Date.getMonth() << "/" << Date.getYear();
formattedDate = ss.str();
return formattedDate;
}