C++将数据从堆栈放到文件
C++ put data from stack to file
我仍然没有太多的C++知识,我想为一项任务寻求帮助。我必须创建一个堆栈,其中填充了键盘输入的数据和整个堆栈以写入外部堆栈。我已经制作了显示堆栈的函数推送、弹出和简单的程序,但在此之前数据必须写入外部文件。任何人都可以帮我处理外部文件吗?
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
struct elem
{ int key; elem *next;} *start=NULL, *p;
void push(int n)
{
p=start;
start=new elem;
start->key=n;
start->next=p;}
int pop(int &n){
if (start)
{
n=start->key;
p=start;
start=start->next;
delete p;
return 1;
}
else
return 0;
}
int main(){
int num;
cout<<"Input integers:"<<setw(10);
while (cin>>num)
{
push(num);
}
cout<<endl<<"Stack:"<<endl;
while(pop(num))
{
cout<<num<<endl;
}
return 0;
}
//您可以使用此伪代码
ofstream outFile;
while(start!=-1){
outFile << pop() << endl;
相关文章:
- WinDbg 不显示某些小型转储文件的完整堆栈跟踪
- OpenCV 3 Visual Studio 2017 调试,调用堆栈没有.pdb文件
- RPN计算器使用头文件进行计算操作和堆栈;用于堆栈的矢量
- 读取文件时检测到堆栈粉碎
- 如何在 C++ 中将从文本文件中读取的元素推送和弹出到数组中,并按 Revserse 顺序输出堆栈?
- 当外部源代码中发生异常时,无法正确使用自创建的小型转储文件的堆栈跟踪
- 为什么在编译时需要知道对象的内存配置文件以进行堆栈放置?
- 从堆栈中读取字符后,如何修复不正确的文件输出
- 我在 36603 以上输入的任何数组大小时都会返回"堆栈溢出"错误。如何使字符串能够捕获整个.txt文件?
- GCC 需要大量内存来编译堆栈上具有非常大对象的 C++ 文件
- 仅针对特定可执行文件增加堆栈大小
- 链表堆栈头文件中"<"标记之前的预期初始值设定项
- 由procexp(MS process explorer)创建的VC10调试转储文件-只有堆栈信息,没有变量值
- 堆栈内存错误创建核心文件
- 使用C++堆栈/队列分析XML文件
- 如何在C++中将文件路径作为节点添加到树或堆栈中
- 如何在 Linux 下为可执行文件分配堆栈
- 在没有PDB文件的情况下,是否可以在Windows上获得堆栈跟踪?如果是,如何
- 如何将linux demon/服务的堆栈跟踪保存到外部文件中
- C++ 使用单个输入字节文件的不同部分实例化堆栈上的成员类