std::queue 中top函数的用法

我是老孟 2004-07-20 10:27:14
std::queue<char> q;
char c = q.top();
编译的时候出现:
error C2039: 'top' : is not a member of 'queue<char,class std::deque<char,class std::allocator<char> > >'
Error executing cl.exe.
...全文
799 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangrk 2004-09-28
  • 打赏
  • 举报
回复
Function Implemented operation
empty() Returns true if the collection is empty
size() Returns number of elements in collection
front() Returns (but does not remove) the element at the front of the queue
back() Returns the element at the end of the queue
push(newElement) Pushes a new element on to the end of the queue
pop() Removes (but does not return) the element at the front of the queue
longj 2004-09-28
  • 打赏
  • 举报
回复
top是 优先队列 priority_queue的成员,返回保存类型的const型的最大值
如果一个priority_queue有10,20,30,25四个元素,那么
const int& i = myqueue.top();
i是30
kaphoon 2004-07-21
  • 打赏
  • 举报
回复
std::priority_queue
它又top()成员函数
而std::queue没有
Jinhao 2004-07-21
  • 打赏
  • 举报
回复
没top,应该是
char c = q.front();

2000的msdn里 写的是top(),但std::queue根本没这东西
RookieStar 2004-07-20
  • 打赏
  • 举报
回复
我记得top好像不是成员函数吧,是个public field。

直接char c = q.top;试试。

24,857

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧