c++运行程序时出现“This application has requested the Runtime...in an unusual way”

来源:互联网 发布:苹果手机远程抹除数据 编辑:程序博客网 时间:2024/04/30 15:17

【Problem】

当我使用c free编写C++时,第一个发现对文件进行操作时,ios::noCreate已经不再使用了,第二个就是在执行下面的程序时出
现提示:This application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information.

代码如下:

//随机访问二进制数据文件#include<fstream>using namespace std;struct student{   //定义Student结构体   int num;   char name[5];   float score; };int main(){    struct student stud[5]={  //初始化五个学生的基本信息        {1001,"Li",85},        {1002,"Fun",97.5},        {1003,"Wang",54},        {1006,"Tan",76.5},        {1010,"Ling",96}    };    fstream iofile("stud.dat",ios::in|ios::out|ios::binary);    //用fstream类定义输入输出二进制文件流对象iofile    if(!iofile){        cerr<<"open error!"<<endl;        abort();    }     for(int i=0;i<5;i++){    //向磁盘文件输出5个学生的数据         iofile.write((char *)&stud[i],sizeof(stud[i]));     }    struct student stud1[5];    for(int i=0;i<5;i=i+1){        iofile.seekg(i*sizeof(stud[i]),ios::beg);//定位于第0,2,4学生数据的开头        iofile.read((char *)&stud1[i/2],sizeof(stud1[0]));        //先后读出三个学生的数据,存放到stud1[0],stud1[1],stud1[2]中        cout<<stud1[i/2].num<<" "<<stud1[i/2].name<<" "<<stud1[i/2].score<<endl;        }     cout<<endl;    stud[2].num=1012;    strcpy(stud[2].name,"Wu");    stud[2].score=60;    iofile.seekp(2*sizeof(stud[0]),ios::beg);        //定位于第三个学生数据的开头     iofile.write((char *)&stud[2],sizeof(stud[2]));  //更新第三个学生的数据     iofile.seekg(0,ios::beg);    for(int i=0;i<5;i++){        iofile.read((char *)&stud[i],sizeof(stud[i]));        cout<<stud1[i/2].num<<" "<<stud1[i/2].name<<" "<<stud1[i/2].score<<endl;    }     iofile.close();     return 0;}

【求助】

我在网上百度之后发现网上提供的办法如下:

1、进入命令行cmd
2、切换目录至windows下的system32(即 cd c:\Windows\System32)
3、执行Regsvr32 Msxml3.dll

我按照上面的流程走了一遍,发现there is no use.Sading~

之后我发现了另一种办法:
下载一个软件Dependency Walker 2.2,解压之后运行depends.exe,然后在里面打开你所要检查的.exe文件(我把我上面代码生成的可执行文件导入进去),然后你就会看到红色字体的消息,这里面就提示了你错误的消息。

其实就是缺少了很多.dll文件,这些文件都可以在脚本之家找到,将其放在System32文件夹里即可。


实在不懂为什么会少这些库文件,求有心人告知,万分感谢!

0 0
原创粉丝点击