VS Code include<iostream>报错

"cannot open source file \"iostream\". Please run the 'Select IntelliSense Configuration...' command to locate your system headers."

根据在网上查找的经验,我改了以下两个地方之后就没有报错了

一、修改Compiler

通过ctrl+shift+P 然后输入下面圈出来的

然后进入下面页面后,将下图中圈出来的部分修改成图上的gcc.exe

二、更改c++文件后缀名为.cpp

.

/boy.h #pragma once// 原有的Boy类定义 class Boy { public: Boy(Boy* pPosition, int id); void leave(Boy* pPosition); void print(); Boy* next(); protected: int code; Boy* pNext; }; //boy.cpp #include"Boy.h" #include<iostream> using namespace std; Boy::Boy(Boy* pPosition, int id)//pPosition为上一个小孩的指针 { code = id; if (!pPosition)//判断是否存在 { this->pNext = this; } else { this->pNext = pPosition->pNext; pPosition->pNext = this; } } void Boy::leave(Boy* pPosition) { pPosition->pNext = this->pNext; cout << "本轮淘汰者编号:" << code << endl; } void Boy::print() { cout << "选手的编号:" << code; } Boy* Boy::next() { return pNext;//下一个选手的首地址 } //Ring.h #pragma once #include"Boy.h" class Ring { public: Ring(); Ring(int n); ~Ring(); Boy getwinner(int m); private: void countUpTo(int m);//数间隔数 Boy* pFirst; Boy* pCurrent; }; #include<iostream> #include"Boy.h" #include"Ring.h" using namespace std; Ring::Ring(){}; Ring::Ring(int n) { pFirst = pCurrent = new Boy(NULL, 1); Boy* pB = pFirst;//pB始终为前一个男孩的指针,用于循环 for (int i = 2; i <= n; i++) { pB = new Boy(pB, i); } } Boy Ring::getwinner(int m)//m为间隔数 { while (pCurrent != pCurrent->next()) { countUpTo(m);//应要包含1.数操作;2.输出淘汰编号;3.让淘汰者离开 } Boy win(pCurrent);//拷贝构造 delete pCurrent; return win; } void Ring::countUpTo(int m) { Boy plast = pCurrent; for (int i = m; i>1; i--)//做了m-1轮 { plast = pCurrent; pCurrent = plast->next();//到下一个人 } pCurrent->leave(plast);//输出淘汰编号,让淘汰者上一个指针指向下一个的首地址 delete pCurrent; pCurrent->next(); } Ring::~Ring(){}; //Jose.h #pragma once #include"Boy.h" #include"Ring.h" #include<iostream> using namespace std; class Jose { public: Jose(int boys, int interval);//boys是小孩总数,interval是间隔数 ~Jose(); Boy gameBegin(); void nextcompetition(); private: int numberofboys; int m; Ring* ring;//含有其他类对象是啥方法? Boy* win; }; //Jose.cpp #include"Boy.h" #include"Jose.h" #include"Ring.h" #include<iostream> using namespace std; Jose::Jose(int boys, int interval) { numberofboys = boys; m = interval; ring = new Ring(boys); win = NULL; } Jose::~Jose() { delete ring; delete win; } Boy Jose::gameBegin() { if (!win) { win = new Boy(ring->getwinner(m)); } else { cout << "已进行过比赛结果,若要重复比赛,请将win调为空指针"; } return *win; } void Jose::nextcompetition() { this->win = NULL; } //main.cpp #include"Boy.h" #include"Jose.h" #include"Ring.h" #include<iostream> using namespace std; void main() { cout << "请输入参加小孩个数:"; int n; cin >> n; cout << endl; cout << "请输入间隔数:"; int m; cin >> m; cout << endl; Jose one(n, m); cout << "第一场胜利者:"; one.gameBegin().print(); system("pause"); }访问this指针报错
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值