在我的程序运行期间出现了一些问题,我无法解决问题所在。
基本上会发生什么,我的程序自动关闭并在 Microsoft visual c ++ 2010 express 窗口中显示以下内容
这可能是什么原因?我不知道为什么会这样。
让我告诉我在我的程序中我经常使用指针并使用了我写入光盘的字符数组
该程序太大而无法显示
这是我的程序停止后调用的函数:
void display_databases()
{
struct info_of_trains
{
int train_no;
char train_name[25];
char boarding_pt[25];
char destination[25];
int first_seats;
int fare_first;
int second_seats;
int fare_second;
char date[20];
};
info_of_trains e;
cout<<"TRno. TRname B.pt D.pt F.seats F.fare S.seats F.second Date\n";
FILE *fp;
fp=fopen("database","r");
if(fp==NULL)
{
cout<<"failure";
}
else
{
while(fread(&e,sizeof(e),1,fp)==1)
{
printf(e.train_no,e.train_name,e.boarding_pt,e.destination,e.first_seats,e.fare_first,e.second_seats,e.fare_second,e.date);
cout<<"-------------------------------------------------------------------------------\n";
}
fclose(fp);
}
}
这是执行停止的地方:!
答案 0 :(得分:1)
您似乎遇到了断点,或者您的程序存在访问冲突(读取非法指针)。您似乎也已经最大化/分离了调试面板。您可以通过将顶部的黄色栏拖动到屏幕的下半部分来重新连接面板。
在它发生之前你收到了警告信息吗?否则,您是否定义了断点(单击代码编辑器的左边距,因此会出现一个红色圆圈)
编辑:正如评论中所指出的,错误的发生是因为您使用了printf
错误的方法。改为使用cout
,如上所述:
cout << e.train_no <<" " << e.train_name << " " << e.boarding_pt << " " << e.destination << " " << e.first_seats << " " << e.fare_first << " " << e.second_seats << " " << e.fare_second << " " << e.date << endl;