age*_*off 1 c++ stack reverse text 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 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;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么我得到一个编译错误"在outfile中不匹配operator <<".
pop()回报void,而不是std::string.使用top()然后pop():
while(!lines.empty())
{
outfile << lines.top() << endl;
lines.pop();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1362 次 |
| 最近记录: |