作为新手小白,我喜欢在一个项目中写多个小程序来调试运行,因为每次新建一个项目都显得比较繁琐。但一个项目中包含多个main函数,项目是无法运行的。查了一些资料终于可以完美解决这个问题,以VS2017为例。
一个项目中有3个cpp文件,每个均含有main()函数,
1.批量排除不需要调试的文件按住Shift或者Crtl选中多个要排除的文件,鼠标右键设置排除后,选中的文件都会被排除
①先把003源文件排除,
②然后在真实的目录结构中恢复002源文件,让002包含在项目中即可
虚拟目录并不是真实的文件目录结构
切换到真实的文件目录结构,新建一个src文件,把源文件放入到src中方便管理
学习了冒泡排序
#include<iostream>#include<string>#include<ctime>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 ((stu[i].score) > (stu[i + 1].score)) { temp = stu[i]; stu[i] = stu[i + 1]; stu[i + 1] = temp; } } }}
本站所有软件信息均由用户上传发布,版权归原著所有。如有侵权/违规内容,敬请来信告知邮箱:764327034@qq.com,我们将及时撤销! 转载请注明出处:https://www.ssyg068.com/kuaixun/2053.html
发表回复
评论列表(0条)