0

尝试编译以下函数时出现以下错误:

Error: invalid operands of types int and const char [3] to binary operator

我该如何解决?

string getFormattedDate()
{
    formattedDate = Date.getDay() << "/" << Date.getMonth() << "/" << Date.getYear();
    return formattedDate;
}
4

1 回答 1

8

你不能这样做,它不是有效的 C++。也许你想要:

#include <sstream>

// ...

string getFormattedDate()
{
    std::ostringstream ss;
    ss << Date.getDay() << "/" << Date.getMonth() << "/" << Date.getYear();
    formattedDate = ss.str();
    return formattedDate;
}
于 2013-09-03T07:06:56.420 回答