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

标签 c++ string cout

为什么我不能像这样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/

相关文章:

swift - ExpressibleByStringLiteral 在函数参数中带有 optional 项

c++ - 避免在 C++ MPI 中为 cout 重复 if 语句

c++11 - 在 C++ 流中使用三元运算符可以吗?

c++ - 从第一类型的第二个非类型参数推导第一类型

c++ - std::map 按数据排序?

用多个结束分隔符分割字符串

python - 如何对字符串列表中的每个单独的字符串进行排序?

流运算符的 C++ 问题

c++ - Xcode All Exceptions 断点 - 忽略某些 C++ 异常

c++ - GTK 主题引擎 : where to start?