473,796 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why this program is incorrect?

Hi,

I am trying to get the iterator that points to the last element of a
deque.
However, the following program is incorrect:

#include <deque>
#include <iostream>
using namespace std;

int main()
{
deque<int> queue;
deque<int>::ite rator it;

queue.clear();
queue.push_back (5);
it = queue.rbegin(). base();

cout<<"*it = "<<*it<<end l;
return 0;
}

How can I get a correct one?
Thanks a lot!

Andy

Jul 23 '05 #1
4 1140
well, it = (queue.rbegin() + 1).base() will work.
andy

Jul 23 '05 #2
Andy wrote:
I am trying to get the iterator that points to the last element of a
deque.


/**/ std::deque<int> queue;
/**/ queue.push_back (5);
/**/ std::deque<int> ::iterator it = queue.end() - 1;
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #3
On 2005-02-01 09:39:31 -0500, "Andy" <gn***@yahoo.co m> said:
well, it = (queue.rbegin() + 1).base() will work.
andy


Why even bother with reverse iterators? Why not just use:

it = queue.end() - 1;

--
Clark S. Cox, III
cl*******@gmail .com

Jul 23 '05 #4
Andy wrote:
Hi,

I am trying to get the iterator that points to the last element of a
deque.
However, the following program is incorrect:

#include <deque>
#include <iostream>
using namespace std;

int main()
{
deque<int> queue;
deque<int>::ite rator it;

queue.clear();
queue.push_back (5);
it = queue.rbegin(). base();

cout<<"*it = "<<*it<<end l;
return 0;
}

How can I get a correct one?
Thanks a lot!

Andy


Hi,

base() returns an iterator one beyond the element pointed to by the
corresponding reverse_iterato r so you need

it = --(queue.rbegin() .base());

instead.

/Andreas

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2906
by: muser | last post by:
Karl this is albeit your program, in the program that you wrote for me I learned quite alot, i didn't realise I could return NULL for instance or even use functions without first declaring them, but this is where I'm encountering resistance, as all the bool functions are compiling with the error: local function definitions are illegal. I've never used using namespace std before and was wondering if you had created a header file in...
3
1375
by: Ralph Purtcher-Wydenbruck | last post by:
This is a worrying bug, and indicates a potential problem in the Framework CLR. This bug affected a project I was working on, which behaved differently when run from the Visual Studio IDE than when run by double clicking on the project's EXE file. The problem can be replicated easily: Create a new project in Visual Studio 2003 and add the following code. Module Main Sub Main()
7
13270
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and the rank and suit of its second card. Note that the two cards in a hand may be entered in any order; it’s not necessarily the case that the highest card will appear first, for example. Your program will then determine whether the hand is valid, and...
2
1814
by: gilllyo | last post by:
I'm trying to run a program and pass it arguments. I know that the arguments provided are correct but I get a "The Parameter is incorrect" error. I has used the exact same arguments as provided in the 'arg' string to the program on the console and it worked as expecterd. (I copied the text directly from a watch I had set up) I am using C#. Is there anything that I have missed? Thank you. System.Diagnostics.ProcessStartInfo si...
5
46321
by: Lloyd Dupont | last post by:
Hi All! I have this application of mine which works well. It even used to work on Vista. (I work on XP most of the time). There are some ManagedC++ assemblies in the project. Now when I try to start the project under vista, when I try to access classes in the ManagedC++ assemblies I get this error:
3
8163
by: Ron Jackson | last post by:
I am using Python 2.5 on Windows XP. I have installed Pyserial and win32all extensions. When I try to run the example program scan.py (included below), or any other program using pyserial, as soon as it hits the statement: s = serial.Serial(i) I get the error:
3
2952
by: kaka_hunter | last post by:
#include <iostream> #include <fstream> using namespace std; const int max_tries=7; int earnings=0; int wordnum; void getword () { ifstream fin;
20
2299
by: Robbie Hatley | last post by:
I needed a quick program called "random" that gives a random positive integer from n1 to n2. For example, if I type "random 38, 43", I want the program to print a random member of the set {38, 39, 40, 41, 42, 43}. Also, I read in my compiler's documentation the following: To get a random number in the range 0..N, use rand()%(N+1). Note that the low bits of the rand's return value are not very random, so rand()%N for small values of N...
6
2883
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.