C++ 如何为';迭代计数器';。txt?
我在while循环中有以下内容,它按预期工作(它为先前定义的ifstream的每一行创建新的ofstream和.txt文件),但它用垃圾填充它们。我不熟悉这门语言,似乎不明白为什么。任何帮助都会很好C++ 如何为';迭代计数器';。txt?,c++,ifstream,ofstream,C++,Ifstream,Ofstream,我在while循环中有以下内容,它按预期工作(它为先前定义的ifstream的每一行创建新的ofstream和.txt文件),但它用垃圾填充它们。我不熟悉这门语言,似乎不明白为什么。任何帮助都会很好 ofstream lineOutFile; string newFileName; stringstream linefile; linefile << lineCt; linefile >> newFileName; newFileName += ".txt"; l
ofstream 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";
}
lineOutFile << "The corrected 5' x 3' comple...." << ect...;
lineOutFile.close();
lineCt++;
流式管线输出文件的;
字符串newFileName;
字符串流行文件;
linefile>newFileName;
newFileName+=“.txt”;
lineOutFile.open(newFileName.c_str());
如果(!lineOutFile)
{
cerr你输出的这些变量都是什么?它们来自程序的早期部分。它们是合理的,我试着去输出它们,它们是我想要的。我没有立即发现任何问题。A会有帮助。输出的到底是什么?你看到“修正的5'x'3…”?此外,请尝试删除所有已创建的文件,然后重新运行程序。您正在执行插入操作,甚至在流的文件打开之前。