返回信息流求问这段代码需不需要释放内存,如果需要的话,该如何释放?
#include <fstream>
#include <iostream>
#include <queue>
using namespace std;
int main()
{
ifstream stop;
stop.open("stop.txt");
queue<char*> q;
for(int i=0;i<5;i++)
{
char *s=new char[15];
//stop.getline(s,'\n');
cout<<s<<endl;
q.push(s);
}
while (!q.empty())
{
cout << q.front() << endl;
delete[]q.front(); //疑惑在这里
q.pop();
}
if(q.empty())
cout << "is empty" <<endl;
return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #75227同步于 2013/11/16
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
求问 stl 中 queue<char*>
strugglingL
2013/11/16镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
就是啊,这不就完了吗,有什么坑?
【 在 iam19891211 (【意涵团】_阿守_) 的大作中提到: 】
: 那么释放是对的,就是对指针delete,不知道你的疑惑是什么。
通过『我邮』发布