Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 返回垃圾的流。不能工作。。。为什么';流的t?_C++_Fstream_Cout_Stringstream_Ostream - Fatal编程技术网

C++ 返回垃圾的流。不能工作。。。为什么';流的t?

C++ 返回垃圾的流。不能工作。。。为什么';流的t?,c++,fstream,cout,stringstream,ostream,C++,Fstream,Cout,Stringstream,Ostream,所以我试图设计一个程序,输入一个文件,然后读取每一行,将每一行的信息输出到一个新文件中 我都记下来了。。。除了我所有的.txt文件都充满了垃圾,而不是它们应该填充的内容 我想不出来。如果我无法将输入的字符串输入ofstream,屏幕上会打印出正确的内容 fstream lineOutFile; string newFileName; stringstream linefile; linefile << lineCt; linefile >> newFileName;

所以我试图设计一个程序,输入一个文件,然后读取每一行,将每一行的信息输出到一个新文件中

我都记下来了。。。除了我所有的.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++;

}
fstream lineOutFile;
字符串newFileName;
字符串流行文件;
linefile>newFileName;
newFileName+=“.txt”;
lineOutFile.open(newFileName.c_str());
如果(!lineOutFile)
{
cerr试着跑步

LANG=C your_program

并在编辑器中关闭编码识别。更好的方法是使用
cat
程序查看txt文件。

为什么要使用
fstream
而不是流的


fstream
的默认值是打开一个现有文件。流的默认值是从一个空文件开始。文件中已有的内容可能会导致编辑器用错误的编码解释数据。

是否可以将.txt文件解释为Unicode(UTF-16)当你阅读它们时?你会看到垃圾(虽然在8位编码中这看起来是正确的)。我怎么知道呢?我的输入文件似乎是Unicode(UTF-8)。对吗?你在使用什么文本编辑器?Gedit。我只是通过终端拉一个文本文档。。。