(新手请教)关于为什么添加换行符就使代码无法正常动作的情况
本人是新手,请求高手支招:
我编了一个查询时时彩连续三十期未出0的历史记录程式,此程式已能正常动作:
程式代码如下:
//时时彩三十期未出0,历史查询
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct lottery
{
string phase; //声名字符串,储存时时彩的期号
char number[5]; //声名数组,储存每期时时彩的开奖号码
}property[300000]; //声名三十万个成员的结构数组,储存时时彩每期的历史记录
int main()
{
char filename[50] = "shishicai.txt"; //声名字符型数组储存时时彩历史数据文档名
ifstream infile; //声名ifstream变量
infile.open(filename); //与文件关联
if(!infile.is_open()) //检查文件是否正常打开
{
cout<<"could not open the file \"demo6_9\"\n";
cout<<"program terminating!\n";
exit(EXIT_FAILURE);
}
for( long i=0; i<300000 && infile.good() ; i++) //将文件数据导入结构
{
infile>>property[i].phase;
char ch;
infile.get(ch);
for( int j=0; j<10 && infile.good() ;j++)
{
if(ch!=',')
{
property[i].number[j/2]=ch;
}
infile.get(ch);
}
}
if (infile.eof())
cout<<"End of file reached.\n";
else if (infile.fail())
cout<<"Input terminated by data mismatch.\n";
else
cout<<"Input terminated for unknown reason.\n";
infile.close();
int count;
for(long j=0;j<300000;j++) //逐个查询property.number[]中的第一个字符,看是否等于‘0’
{
for(int k=0;k<5;k++)
{
if(property[j].number[k]!='0')
count++;
if(property[j].number[k]=='0')
count=0;
if(count==150)
{
cout<<property[j].phase; //如果等于三十期未出0,也就是150个连续开奖号没有0,就显示期号
count=0;
}
}
}
return 0;
}
此程式能正常显示期号。
现在我的问题是,为什么我在显示期号代码后面加上 <<endl; 程式就无法正常显示了,程式将会连续显示换行,直到程式崩溃。