关于 Debug Assertion Failed的问题
编译器为visual studio2010
运行后面程序时,编译无问题,运行后输入相应数字就会出现以下问题:
1.output模块中会给出如下信息:
'Chapter_3Case9.exe': Loaded 'D:\C++\program\Chapter_3Case9\Debug\Chapter_3Case9.exe', Symbols loaded.
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Program Files\360\360Safe\safemon\safemon.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\psapi.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\wininet.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\normaliz.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\iertutil.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\urlmon.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'Chapter_3Case9.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
Microsoft Visual Studio C Runtime Library has detected a fatal error in Chapter_3Case9.exe.
Press Break to debug the program or Continue to terminate the program.
The program '[1212] Chapter_3Case9.exe: Native' has exited with code 0 (0x0).
2.运行后,输入指定值到界面中会弹出对话框,信息如下:
Debug Assertion Failed!
Program:
D:\C++\……\Chapter_3Case9.exe
File:f:\……\fwrite.c
Line:77
Expression:(stream!=NULL)
For information on how your program can cause an assertion failure,see the Visual C++ documentation on asserts.
源程序为:
// Chapter_3Case9.cpp : Defines the entry point for the console application.
//学生信息管理系统
#include "stdafx.h"
#include<iostream>
#include<string>
#include<iomanip>
#define infile "data.txt"
using namespace std;
struct Student
{
char num[9];
int age;
char name[20];
char sex[8];
char nation[10];
char home[20];
}stud[1000],exchange,ins;
void init(),update(),delet(),query(),insert(),stat(),show();
int _tmain(int argc, _TCHAR* argv[])
{
char opt;
int exp=1;
cout<<"*****这里是学生信息管理系统,欢迎您光临!*********"<<endl;
while(exp)
{
cout<<"\n\n************************************";
cout<<"\n****** 1、初始系统信息 ********";
cout<<"\n****** 2、显示学生信息 ********";
cout<<"\n****** 3、插入学生信息 ********";
cout<<"\n****** 4、删除学生信息 ********";
cout<<"\n****** 5、查找学社信息 ********";
cout<<"\n****** 6、修改学生信息 ********";
cout<<"\n****** 7、学生信息统计 ********";
cout<<"\n****** 8、退出查询系统 ********";
cout<<"\n\n************************************";
cout<<"\n根据以上提示,请选择你要进行的项目:";
cin>>opt;
switch(opt)
{
case '1': init(); break;
case '2': show(); break;
case '3': insert(); break;
case '4': delet(); break;
case '5': query(); break;
case '6': update(); break;
case '7': stat(); break;
case '8':
{
exp=0;
cout<<"欢迎您的光临,再见!\n";
}
break;
default:
cout<<"输入错误,请重新输入!\n";
break;
}
}
}
void writefile(int n) //将数据写入文件
{
FILE *fp;
fopen_s(&fp,infile,"w");
for(int i=0;i<n;i++)
if(fwrite(&stud[i],sizeof(struct Student),1,fp)!=1) /*向stud[i]中写入fp指针所指向的文件内容,每个元素长度为sizeof(struct Student)
且每次只写入一个元素项,写入成功则返回所写入项的个数,不成功,则返回0.*/
cout<<"\n输入错误!";
fclose(fp);
}
void readfile(int n)
{
FILE *fp;
cout<<" 学号 姓名 年龄 性别 民族 籍贯 \n";
fopen_s(&fp,infile,"w");
for(int i=0;i<n;i++)
{
fwrite(&stud[i],sizeof(struct Student),1,fp);
cout<<setw(8)<<stud[i].num<<setw(8)<<stud[i].name
<<setw(8)<<stud[i].age<<setw(8)<<stud[i].sex
<<setw(8)<<stud[i].nation<<setw(8)<<stud[i].home<<endl;
}
fclose(fp);
}
[解决办法]
我这运行是好的啊,你可以把你的程序发个我,dragoo747450@163.com
[解决办法]
摒弃cin、cout;
使用scanf、printf,并检查scanf的返回值。
[解决办法]
摒弃cin、cout;
使用scanf、printf并检查scanf的返回值。
[解决办法]
- C/C++ code
//printf里面的%和变量的一一对应关系//scanf里面的%和变量以及变量前加不加&的一一对应关系//是C代码中非常容易出错的地方,而且通常编译还不出错。//所以在编译源代码之前值得专门仔细检查一遍甚至多遍。struct Student { char num[ 9]; int age ; char name[20]; char sex[ 8]; char nation[10]; char home[20];} stud[1000],exchange,ins;//...void s_gets(char *s,int len) { fgets(s,len-1,stdin); if ('\n'==s[strlen(s)-1]) s[strlen(s)-1]=0;}void s_getn(int *pi,int minv,int maxv) { while (1) { rewind(stdin); if (1==scanf("%d",pi) { if (minv<=pi[0] && pi[0]<=maxv) break; } }}void init() //输入学生的信息{ int i,N; printf("请输入您想要进行管理的学生数目:(1..1000)");fflush(stdout); while (1) { rewind(stdin); if (1==scanf("%d",&N) { if (1<=N && N<=1000) break; } } for (i=0;i<N;i++) { printf("请输入第%d个学生的信息:\n",i+1); printf("学号\n");s_gets( stud[i].num , 9); printf("年龄\n");s_getn(&stud[i].age , 7,200); printf("姓名\n");s_gets( stud[i].name ,20); printf("性别\n");s_gets( stud[i].sex , 8); printf("民族\n");s_gets( stud[i].nation,10); printf("籍贯\n");s_gets( stud[i].home ,20); printf("%10s",stud[i].num ); printf("%4d" ,stud[i].age ); printf("%21s",stud[i].name ); printf("%9s" ,stud[i].sex ); printf("%11s",stud[i].nation); printf("%21s",stud[i].home ); printf("\n"); }}