[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
前言
最近我个人在写代码然后生成的.exe的程序一运行就闪退,然后就没爱了,之后我在度娘上找了如下的几个方法可以解决这个问题,下面就给大家说说吧!
方法之一
在代码段末尾加上getch();就可以了,不过要加入头文件#include comio.h(代码段末尾指你程序要执行完之前, 一般在return
0;之前)或者,加上getchar(); 也行。
原理就是停止,等待用户输入,即你没输入的话,程序就不算执行完毕。
差别:加getch();是按任意键退出,而getchar();,你可以输入若干个字符然后按回车才会结束。
方法之二
加个头文件#include “stdlib.h”,然后在代码段末尾加个
system(“pause”);这里的system就是调用从程序中调用系统命令(和shell命令)。
#include "stdio.h"
#include "stdlib.h"//加入这个
void main()
{
.........
system("pause");//以及这个
}
system(“pause”)就是从程序里调用“pause”命令;
而“pause”这个系统命令的功能很简单,就是在命令行上输出一行类似于“Press any key to
exit”的字,等待用户按一个键,然后返回。还是同样的道理,等待用户输入,才能算执行完毕。
方法之三
在exe文件同目录下新建一个txt文档,里面输入如下内容
xx.exe
pause
然后退出保存,把后缀txt改为bat然后运行,那个xx就是文件的名字。然后打开.bat文件运行程序。(.bat文件命名随意)这里的.bat文件是批处理文件(也被称为批处理程序或脚本)是无格式的文本文件,它包含一条或多条命令。它的文件扩展名为
.bat 或
.cmd。在命令提示下键入批处理文件的名称,操作系统就会按照该文件中各个命令出现的顺序来逐个运行它们。(使用批处理文件,可以简化日常或重复性任务。)
方法对不同的程序肯定有不适用,方法不唯一!