因此,我正在尝试设计一个程序,该程序输入文件,然后逐行读取并接受每一行,并将有关该文件的信息输出到新文件。我全都失望了...除了!我所有的.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文件是垃圾文件? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 为什么要使用fstream而不是ofstream?fstream的默认设置是打开现有文件。 ofstream的默认值是从一个空文件开始。文件中已有的文件都可能导致您的编辑器使用错误的编码来解释数据。 (adsbygoogle = window.adsbygoogle || []).push({}); 07-26 07:39