gpt4 book ai didi

c++ - 为什么我不能找到一个字符串?

转载 作者:IT老高 更新时间:2023-10-28 11:33:18 25 4
gpt4 key购买 nike

为什么我不能像这样cout string:

string text ;
text = WordList[i].substr(0,20) ;
cout << "String is : " << text << endl ;

当我这样做时,我收到以下错误:

Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\mollasadra\documents\visual studio 2008\projects\barnamec\barnamec\barnamec.cpp 67 barnamec**

令人惊讶的是,即使这样也不起作用:

string text ;
text = "hello" ;
cout << "String is : " << text << endl ;

最佳答案

你需要包含

#include <string>
#include <iostream>

关于c++ - 为什么我不能找到一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6320995/

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