
编了一个C++程序,出现**.exe已停止工作,帮忙解决一下,谢谢! 10
#include<iostream>#include<string>#include<fstream>usingnamespacestd;intmain(){cout<<...
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
cout<<"Engineering Journal – Gao Wei";
int x;
string in;
char z;
string item[10];
int n=0;
char str[3];
int pin[3];
while (1)
{
cout << "\nEnter your 4 digit pin number:";
getline(cin,in);
cin.ignore(100,'\n');
x=in.length();
if(x==4)
{
strcpy(str,in.c_str());
if(str[0]<'0'||str[0]>'9')
cout<<"invald pin";
else if(str[1]<'0'||str[1]>'9')
cout<<"invald pin";
else if(str[2]<'0'||str[2]>'9')
cout<<"invald pin";
else if(str[3]<'0'||str[3]>'9')
cout<<"invald pin";
else break;
}
else
cout<<"invald pin";
}
pin[0]=str[0]-'0';
pin[1]=str[1]-'0';
pin[2]=str[2]-'0';
pin[3]=str[3]-'0';
while(1)
{
cout<<"Select option ([L]ist Titles, [D]isplay Item, [A]dd Item, [Q]uit): ";
cin>>z;
cout<<endl;
z=toupper(z);
if (z=='L')
{
string s;
ifstream fin("journal.txt");
if(!fin)
{
cout<<"open error"<<endl;
exit(1);
}
int i=1;
while (getline(fin,s))
{
cout<<i<<". "<<s<<endl;
fin.ignore(1000,'\n');
fin.ignore(1000,'\n');
fin.ignore(1000,'\n');
i++;
}
}
if(z=='D')
{
int o;
cout<<"please enter item number: ";
cin>>o;
string t;
ifstream fin("journal.txt");
while (fin.ignore(1000,'\n'))
{
fin.ignore(1000,'\n');
getline(fin,t);
int y=t.length();
for(int z=0;z<y;z++)
{
t[z]=t[z]-pin[z%4];
}
item[n]=t;
fin.ignore(1000,'\n');
n++;
}
cout<<item[o-1]<<endl;
}
}
return 0;
}
有病啊 展开
#include <string>
#include <fstream>
using namespace std;
int main()
{
cout<<"Engineering Journal – Gao Wei";
int x;
string in;
char z;
string item[10];
int n=0;
char str[3];
int pin[3];
while (1)
{
cout << "\nEnter your 4 digit pin number:";
getline(cin,in);
cin.ignore(100,'\n');
x=in.length();
if(x==4)
{
strcpy(str,in.c_str());
if(str[0]<'0'||str[0]>'9')
cout<<"invald pin";
else if(str[1]<'0'||str[1]>'9')
cout<<"invald pin";
else if(str[2]<'0'||str[2]>'9')
cout<<"invald pin";
else if(str[3]<'0'||str[3]>'9')
cout<<"invald pin";
else break;
}
else
cout<<"invald pin";
}
pin[0]=str[0]-'0';
pin[1]=str[1]-'0';
pin[2]=str[2]-'0';
pin[3]=str[3]-'0';
while(1)
{
cout<<"Select option ([L]ist Titles, [D]isplay Item, [A]dd Item, [Q]uit): ";
cin>>z;
cout<<endl;
z=toupper(z);
if (z=='L')
{
string s;
ifstream fin("journal.txt");
if(!fin)
{
cout<<"open error"<<endl;
exit(1);
}
int i=1;
while (getline(fin,s))
{
cout<<i<<". "<<s<<endl;
fin.ignore(1000,'\n');
fin.ignore(1000,'\n');
fin.ignore(1000,'\n');
i++;
}
}
if(z=='D')
{
int o;
cout<<"please enter item number: ";
cin>>o;
string t;
ifstream fin("journal.txt");
while (fin.ignore(1000,'\n'))
{
fin.ignore(1000,'\n');
getline(fin,t);
int y=t.length();
for(int z=0;z<y;z++)
{
t[z]=t[z]-pin[z%4];
}
item[n]=t;
fin.ignore(1000,'\n');
n++;
}
cout<<item[o-1]<<endl;
}
}
return 0;
}
有病啊 展开
2个回答
展开全部
x=in.length();
if(x==4)
{
strcpy(str,in.c_str());
???????????
str的申明是char str[3];
这个错误就能导致崩溃了
if(x==4)
{
strcpy(str,in.c_str());
???????????
str的申明是char str[3];
这个错误就能导致崩溃了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询