不在 VS 上运行,但在开发C++上运行

Doesnt run on VS but runs on Dev C++

本文关键字:运行 开发 C++ VS 不在      更新时间:2023-10-16

我一直在尝试在VS上运行这个基本程序。代码如下

#include<iostream>
using namespace std;
class student
{
public:
int id;
string name;
};
int main()
{
student s1, s2;
s1.id = 10;
s1.name = "ayudh";
s2.id = 20;
s2.name =  "pooja";
cout << s1.id << endl ;
cout << s1.name << endl;
cout << s2.id << endl;
cout << s2.name << endl;
system("pause");
}

当我尝试运行它时,出现错误"没有运算符"<<"与此操作数匹配"。 有人可以帮助我解决问题吗?

你错过了

#include <string>

在文件的顶部。