所以我正在尝试设计一个程序,该程序输入一个文件,然后通读这些行并获取每一行并将有关它的信息输出到一个新文件。
我把这一切都记下来了……除了!我所有的 .txt 文件都充满了垃圾而不是应该填充的内容。
我想不明白。如果我找出要输入到 ofstream 中的字符串,则正确的内容会打印在屏幕上。
fstream lineOutFile;
string newFileName;
stringstream linefile;
linefile << lineCt;
linefile >> newFileName;
newFileName += ".txt";
lineOutFile.open(newFileName.c_str());
if(!lineOutFile)
{
cerr << "Can't open output file.\n";
}
stringstream iss;
iss << "The corrected 5' x 3' complement of line " << lineCt <<
" is as follows - \n\n" << finalSeq << "\n\n\n\n" <<
"This line of DNA sequence is made up of " << cgContent <<
" C and G neucleotides.\n\n" << "It contains " << polyTCount <<
" Poly-T strings of more than 4 consecutive neucleotides. They are as follows. - \n" <<
polyTString << "\n\n There are " << cpgCount <<
" CpG sites. The locations are as follows - \n" << cpgString;
string storage;
storage = iss.str();
cout << storage;
lineOutFile << storage;
lineOutFile.close();
lineCt++;
}
我得到“潣牲捥整✵砠㌠‧”<<我的.txt文件中有这种疯狂。
当我刚刚发现同样的刺痛时,我得到了正确的结果!
为什么我的 .txt 文件是垃圾?