QuBiEngine::QuBiEngine(ifstream& dnaFile)
{
int i = 0;
while(!dnaFile.eof()) //while the file isn't at its end
{
dna.push_back(""); //creates an element
if(!dnaFile.good())//checks for failbits and other errors
{
dna[i] = "Not a valid sequence";
i++;
continue;
}
getline(dnaFile, dna[i]);
//checks to see if the character is valid ie: a, t, c, g
for(int j=0; j<dna[i].length(); j++)
{
dna[i][j] = putchar(tolower(dna[i][j]));
if((dna[i][j]!='a')||(dna[i][j]!='t')||(dna[i][j]!='c')||(dna[i][j]!='g'))
{
dna[i] = "Not a valid sequence";
i++;
break;
}
}
i++;
}
}
如果通过测试,它将把dnaFile
ifstream
中的每一行放入一个 vector 中;如果没有通过,则将无效的东西放入 vector 中。 最佳答案
我想通了,第二条if语句中的i++
使它递增两次,从而溢出了我的 vector 。
关于c++ - 构造函数错误,在崩溃前先打印 'a',然后打印三角形,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16430751/