如何从circular_buffer获取元素 [英] How to get element from circular_buffer

查看:161
本文介绍了如何从circular_buffer获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MAC(xcode)中的boost库.我有两个关于boost::circular_buffer的问题.

I am using boost library in MAC (xcode). I have two questions about boost::circular_buffer.

1-声明Circular_buffer时出现语法错误

1 - I am getting syntax error when declaring the circular_buffer

boost::circular_buffer<int> cb(10);

Expected parameter decelerator
Expected ')'

2-第二个问题是,当我使用push_back将元素添加到boost::circular_buffer时,如何从circle_buffer中提取/获取元素,pop_front没有给出该元素.

2 - Second question is when I add element into boost::circular_buffer using push_back, how to extract / get the element from circular_buffer, pop_front does not give the element.

推荐答案

boost::circular_buffer<T>::front()为您提供对最前面"元素的引用,而boost::circular_buffer<T>::pop_front()会删除该元素.

boost::circular_buffer<T>::front() gives you a reference to the element at the "front", while boost::circular_buffer<T>::pop_front() will remove that element.

boost::circular_buffer<T>::back()为您提供了后面元素的引用,而boost::circular_buffer<T>::pop_back()则删除了该元素.

boost::circular_buffer<T>::back() gives you a reference to the element at the back, while boost::circular_buffer<T>::pop_back() removes that element.

您的语法错误似乎是由最令人讨厌的解析引起的.试试:

It appears your syntax error is resulting from the most vexing parse. Try instead:

boost::circular_buffer<int> cb;
cb.set_capacity(10); 

或更简洁地说:

boost::circular_buffer<int> cb((10));

这篇关于如何从circular_buffer获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆