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

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


我该如何解决?

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

最佳答案

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

#include <sstream>

// ...

string getFormattedDate()
{
    std::ostringstream ss;
    ss << Date.getDay() << "/" << Date.getMonth() << "/" << Date.getYear();
    formattedDate = ss.str();
    return formattedDate;
}

10-08 11:11