注册 登录
编程论坛 C++教室

编译失败问题

qq68677589 发布于 2020-03-03 12:15, 1795 次点击
#include<iostream>
using namespace std;
int main(){
    string str = "c++";
    cout << str << endl;
    system("pause");
}
vs2013显示错误:错误    1    error C2679: 二进制“<<”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)    c:\users\yuan\documents\visual studio 2013\projects\inout1\inout1\源.cpp    6    1    inout1
    2    IntelliSense:  没有与这些操作数匹配的 "<<" 运算符
            操作数类型为:  std::ostream << std::string    c:\Users\yuan\Documents\Visual Studio 2013\Projects\inout1\inout1\源.cpp    5    7    inout1
但在devc++里面运行,又是正常的、请问这是什么原因呢?
6 回复
#2
rjsp2020-03-03 12:43
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str = "c++";
    cout << str << endl;
}
#3
qq686775892020-03-04 00:01
谢谢,我已经知道,但是就不知道为甚其他编译器不用添加string也行
#4
叶纤2020-03-04 18:05
不论是c++还是其他语言都没承认过string是一个类型,不过有些编译器确实把string当作类型来看,如果想跨平台的话建议加string预处理
#5
return_02020-03-05 16:48
大家都说string类string类,但我个人觉得string不是类
#6
maomao123452020-03-24 10:03
我觉得string是个类
#7
lin51616782020-03-24 11:12
回复 5楼 return_0
是一个类
1