下面的代码有什么问题.对于某些输入和某些特殊输入的崩溃,它运行完全正常吗?
#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();
}
Run Code Online (Sandbox Code Playgroud)
它为这些输入而崩溃:输入日期(dd.mm)ankmjjdn md
输入时间(hh:mm:ss)输入contentsnjs sjnsn