Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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++ C++;:使用堆栈反转文本文件中的行_C++_Text_Stack_Reverse_Lines - Fatal编程技术网

C++ C++;:使用堆栈反转文本文件中的行

C++ C++;:使用堆栈反转文本文件中的行,c++,text,stack,reverse,lines,C++,Text,Stack,Reverse,Lines,到目前为止,我有以下代码: #include <stdio.h> #include <stdlib.h> #include <fstream> #include <iostream> #include <string> #include <stack> using namespace std; int main () { ifstream in; in.open("example.txt"); ofstream ou

到目前为止,我有以下代码:

#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main () {


ifstream in;
in.open("example.txt");

ofstream outfile;
outfile.open("out.txt");

stack<string> lines;
string temp;
while(getline(in, temp))
    lines.push(temp);
while(!lines.empty())
    outfile << lines.pop() << endl;

in.close();
outfile.close();

return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main(){
如果输入;
in.open(“example.txt”);
出流孔的直径;
outfile.open(“out.txt”);
叠加线;
字符串温度;
while(getline(in,temp))
线。推(温度);
而(!lines.empty())
outfile返回
void
,而不是
std::string
。然后使用
pop()

while(!lines.empty())
{
outfile返回
void
,而不是
std::string
。然后使用
pop()

while(!lines.empty())
{

outfile AHHH,谢谢。所以我把它改为lines.top(),然后改为lines.pop()。啊,谢谢。所以我把它改为lines.top(),然后改为lines.pop()在那之后。额外的学分-如果你的文件有100万行,这段代码的效果如何?哈,不是家庭作业。我有一个.bmp,我把它转换成二进制,但它是颠倒的。我只需要在开始将二进制转换成十六进制之前翻转它,然后将它放入一个数组中,这样图像就可以继续显示了。小屏幕所以效率不重要。Extr一个学分-如果你的文件有100万行,这个代码工作得如何?哈,不是家庭作业。我有一个.bmp,我把它转换成二进制,但它是颠倒的。我只需要在开始将二进制转换成十六进制之前翻转它,然后把它放入一个数组中,这样图像就可以显示了。小屏幕所以效率并不重要。
while(!lines.empty())
{
    outfile << lines.top() << endl;
    lines.pop();
}