c++中分文件编写为啥报错啊(初学者在学习阶段不要骂我!)

三个文件大概是这样的

img

img

img


纯初学者在看b站黑马这一章 发现自己跑不出来这个代码
人家用的vs 我用的Dev-c
黑马

在图1 cpp文件的最上面加上头文件 #include “swap.h”,这样main()里面才能找到swap函数的定义。
加入位置如下:

#include<iostream>
#include "swap.h"
using namespace std;


这个函数没申明

应该加一句 #include "swap.h"

#include <iostream>
#include "swap.h"
using namespace std;
int main()
{
  int a = 10;
  int b = 20;
  swap(a, b);
  return 0;
}

img


按照你上面的申明,这一行直接 swap(a, b); 就可以,不要加 cout <<


更多可以参考这篇博客:https://www.csdn.net/tags/OtDagg2sODM1OC1ibG9n.html