我收到一条错误消息,显示"<<"标志"no operator matches these operands"

i receive an error saying "no operator matches these operands" for the "<<" signs

本文关键字:lt no 标志 operator matches operands these 一条 消息 显示 错误      更新时间:2023-10-16

我直接从课本上复制这个。

#include <iostream>
using namespace std;
int main()
{
    string myHello = "This is Chapter 3 already?"; 
    cout << myHello << endl; //this part is not working
    return 0;
}

为什么这个代码不起作用?

我试着翻阅这本书寻找解决方案,但没有提供或可用的解决方案。

您需要#include <string>,然后在using namespace命令之上执行即可,如果您取消了namespace命令,则需要执行std::string myhello;

#include <string>