为什么我不能cout一个字符串? [英] Why I cannot cout a string?

查看:220
本文介绍了为什么我不能cout一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why I cannot cout string like this:

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

当我这样做时,会出现以下错误:

When I do this, I get the following error:


错误2错误C2679:binary'< <::没有操作符,它接受类型为'std :: string'的右手操作数(或没有可接受的转换)c:\users\mollasadra\documents\visual studio 2008\projects\barnamec\barnamec\barnamec.cpp 67 barnamec **

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**

这是惊人的,即使这是不工作:

It is amazing, that even this is not working:

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


推荐答案

您需要包含

#include <string>
#include <iostream>

这篇关于为什么我不能cout一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆