作为新手小白,我喜欢在一个项目中写多个小程序来调试运行,因为每次新建一个项目都显得比较繁琐。但一个项目中包含多个main函数,项目是无法运行的。查了一些资料终于可以完美解决这个问题,以VS2017为例。
一个项目中有3个cpp文件,每个均含有main()函数,
1.批量排除不需要调试的文件
按住Shift或者Crtl选中多个要排除的文件,鼠标右键设置排除后,选中的文件都会被排除
![5561b45beefec7783ab07e639907c7a3.png](https://i-blog.csdnimg.cn/blog_migrate/492133af361ed0aae68b380e657e55dc.jpeg)
2.如果我们又想运行源文件002怎么办呢?
①先把003源文件排除,
②然后在真实的目录结构中恢复002源文件,让002包含在项目中即可
虚拟目录并不是真实的文件目录结构
![782c68582c8e1f3e39cb47b284487bc0.png](https://i-blog.csdnimg.cn/blog_migrate/81a57be0d637357519aad26fa5777947.jpeg)
切换到真实的文件目录结构,新建一个src文件,把源文件放入到src中方便管理
![6dd558497bf17e538b1cfce6787d0aba.png](https://i-blog.csdnimg.cn/blog_migrate/a4952e6c423cee8a71b23d459bcd8de2.jpeg)
学习了冒泡排序
#include#include#includeusing 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 <id << "" << (stu + i)->name << "" << (stu + i)->score << "" << (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 ((stu[i].score) > (stu[i + 1].score)) {temp = stu[i];stu[i] = stu[i + 1];stu[i + 1] = temp;}}}}
![5cf0f0f07e4d8f37ed108d5aa42ec96c.png](https://i-blog.csdnimg.cn/blog_migrate/9c110c644ab1cabbd7e06ffc06d4439c.jpeg)