gpt4 book ai didi

c++ - 错误 C2679 : binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:27 24 4
gpt4 key购买 nike

这是我的代码,我该如何修复这个错误?

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
string title = "THE WORLD OF PIRATES";
cout << title << endl;
cout << " Welcome to the world of pirates";

cin.get();

return 0;
}

错误是

binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

最佳答案

你忘了 #include <string>

使用 std::string不包括它的标题适用于某些间接导入部分 <string> 的编译器进入他们的<iostream>或其他 header ,但这不是标准的,不应依赖。此外,当您尝试输出字符串时,它们经常会中断,因为它们仅包含实现的一部分,并且缺少实现 operator<< 的部分。 .

关于c++ - 错误 C2679 : binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51894763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com