vs2017无法打开源文件_C++自学笔记第四天:VS项目中多个源文件分别调试运行

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

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

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

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

5561b45beefec7783ab07e639907c7a3.png

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

①先把003源文件排除,

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

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

782c68582c8e1f3e39cb47b284487bc0.png

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

6dd558497bf17e538b1cfce6787d0aba.png

学习了冒泡排序

#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
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值