gpt4 book ai didi

c++ - glibc 检测到双重释放或损坏

转载 作者:行者123 更新时间:2023-11-30 00:38:02 26 4
gpt4 key购买 nike

<分区>

下面的代码有什么问题。它对某些输入运行得很好,但对某些特殊输入会崩溃?

#include<iostream>
#include<string>
#include<fstream>

using namespace std;


struct event {

string date,time,content;
bool is_high_priority;

};


int main() {

event one,two;
one.is_high_priority=false;
char tmp;

ofstream out_file("events" , ios::binary );


cout<<"\nEnter Date(dd.mm) ";
cin>>one.date;
cout<<"\nEnter Time(hh:mm:ss) ";
cin>>one.time;
cout<<"\nenter content";
cin>>one.content;

if(tmp == 't')
one.is_high_priority = true;
else
one.is_high_priority = false;


out_file.write((char*) &one, sizeof(one) );

out_file.close();


ifstream in_file("events" , ios::binary );
in_file.read((char*)&two,sizeof(two));

cout<<two.date<<" "<<two.time<<" "<<two.content<<" "<<two.is_high_priority;

in_file.close();

}

它因这些输入而崩溃:输入日期(dd.mm) ankmjjdn md

输入时间(hh:mm:ss)输入内容njs sjnsn

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com