现在的位置: 首页 > 综合 > 正文

关于 cin >> string 无法编译的问题

2013年08月30日 ⁄ 综合 ⁄ 共 328字 ⁄ 字号 评论关闭

Visual Studio2008 环境下写了如下两行代码,

 

        string data;
        cin >> data;

 

结果编译时告知 :

 

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

 

云云

 

表面上看是 cin >> 不支持 string,

后来找到问题了

是没有 #include <string> ,

可是我不明白了,为什么没有#include <string>  不在 string data 声明的时候报错,而在负值的时候报错!

不管怎么说,问题是没有#include <string>。

抱歉!评论已关闭.