C++自学笔记第四天:VS项目中多个源文件分别调试运行

C++自学笔记第四天:VS项目中多个源文件分别调试运行

编码文章call10242025-03-20 9:42:0415A+A-

作为新手小白,我喜欢在一个项目中写多个小程序来调试运行,因为每次新建一个项目都显得比较繁琐。但一个项目中包含多个main函数,项目是无法运行的。查了一些资料终于可以完美解决这个问题,以VS2017为例。

一个项目中有3个cpp文件,每个均含有main()函数,

1.批量排除不需要调试的文件

按住Shift或者Crtl选中多个要排除的文件鼠标右键设置排除后,选中的文件都会被排除

2.如果我们又想运行源文件002怎么办呢?

①先把003源文件排除,

②然后在真实的目录结构中恢复002源文件,让002包含在项目中即可

虚拟目录并不是真实的文件目录结构

切换到真实的文件目录结构,新建一个src文件,把源文件放入到src中方便管理

学习了冒泡排序

#include
#include
#include
using namespace std;

struct Student {
	int id;
	string name;
	int score;
	string sex;
};

void PrintData(struct Student *stu, int size);
void Bubble_Sort(struct Student stu[], int size);
int main() {

	srand((unsigned int)time(NULL));//初始化随机数发生器


	struct Student student[] = {
		{10000,"张三",rand() % 41 + 60,"男"},//分数60-100随机
		{10001,"李四",rand() % 41 + 60,"男"},
		{10003,"韩梅梅",rand() % 41 + 60,"女"},
		{10004,"李雷",rand() % 41 + 60,"男"},
		{10005,"韩亚丽",rand() % 41 + 60,"女"},
	};

	int length = sizeof(student) / sizeof(student[0]);//计算学生个数
	cout << "数组长度" << length << endl;

	PrintData(student, length);
	cout <<endl<< "-----冒泡排序后-----" << endl<<endl;
	Bubble_Sort(student, length);
	PrintData(student, length);

	system("pause");
	return 0;
}

void PrintData(struct Student *stu, int size) {
	cout << "编号\t" << "姓名\t" << "成绩\t" << "性别\t" << endl;
	for (int i = 0; i < size; i++) {
		cout << stu i->id << "\t" << stu i->name << "\t" << stu i->score << "\t" << stu i->sex << endl;
	}
}

void Bubble_Sort(struct Student stu[], int size) {//成绩升序排序
	struct Student temp;
	for (int j = 0; j < size-1; j++) {
		for (int i = 0; i < size-j-1 i if stui.score> (stu[i + 1].score)) {
				temp = stu[i];
				stu[i] = stu[i + 1];
				stu[i + 1] = temp;
			}
		}
	}
}

点击这里复制本文地址 以上内容由文彬编程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

文彬编程网 © All Rights Reserved.  蜀ICP备2024111239号-4