没有运算符"+"与这些操作数匹配

No operator "+" matches these operands

本文关键字:操作数 运算符      更新时间:2023-10-16
for (TPathInfoList::iterator iter = pathInfoList.begin(); iter != pathInfoList.end(); ++iter)
{
    const TPathInfoList::value_type& path = *iter;
    EResult resultCode = MakeMSA(path, &msg);
    fs::path parentPath = path.parent_path();
    std::string shortPath = parentPath.parent_path().filename() + "\" + parentPath.filename() + "\" + path.filename();;
    tm t;
    time_t timer;
    timer = time(NULL);
    localtime_s(&t, &timer);
    printf("%04d/%02d/%02d %02d:%02d:%02d [%s] %sn", 
        t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
        msg.c_str(), shortPath.c_str());
}

我正在尝试提升 1.60,但我坚持这个错误。我做错了什么?
http://prntscr.com/a2yync

错误消息

屏幕截图显示parentPath.parent_path().filename()不是字符串,而是filesystem::path

由于shortPath是一个string,我建议parentPath.parent_path().filename().string

std::string shortPath = parentPath.parent_path().filename().string() 
          + "\" + parentPath.filename().string() 
          + "\" + path.filename().string(); 

或者使shortPath成为path并使用与+=运算符的串联

相关文章: