473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple iterator problem

I have made the following code:

std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}

It compiles fine (using MS VS 2008) and when I run it it also prints 0 0 0 1
1 1. But then I get:

Debug Error!

Invalid allocation size 492.....bytes
and I need to pres either abort, try again or ignore. Is this a windows
specific issue?
Aug 2 '08 #1
5 1535

"saneman" <as***@asd.comwrote in message
news:48***********************@news.sunsite.dk...
>I have made the following code:

std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}

It compiles fine (using MS VS 2008) and when I run it it also prints 0 0 0
1 1 1. But then I get:

Debug Error!

Invalid allocation size 492.....bytes
Well I cant see anything wrong with the code. Try running it on its own as
code below

#include <vector>
#include <iostream>

int main()
{
std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}
}


Aug 2 '08 #2
"saneman" <as***@asd.comwrote:
I have made the following code:

std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}

It compiles fine (using MS VS 2008) and when I run it it also prints 0 0 0 1
1 1. But then I get:

Debug Error!

Invalid allocation size 492.....bytes
and I need to pres either abort, try again or ignore. Is this a windows
specific issue?
What is the code that comes after this block?
Aug 3 '08 #3
Daniel T. wrote:
"saneman" <as***@asd.comwrote:
>I have made the following code:

std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}

It compiles fine (using MS VS 2008) and when I run it it also prints 0 0 0 1
1 1. But then I get:

Debug Error!

Invalid allocation size 492.....bytes
and I need to pres either abort, try again or ignore. Is this a windows
specific issue?

What is the code that comes after this block?
It could also be code before that block that is causing the problem.
Aug 3 '08 #4
Rajib <ra*****@verizon.netwrote:
Daniel T. wrote:
"saneman" <as***@asd.comwrote:
I have made the following code:
>
std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}
>
It compiles fine (using MS VS 2008) and when I run it it also
prints 0 0 0 1 1 1. But then I get:
>
Debug Error!
>
Invalid allocation size 492.....bytes
>
>
and I need to pres either abort, try again or ignore. Is this a
windows specific issue?
What is the code that comes after this block?

It could also be code before that block that is causing the problem.
:-) It could be code half-way across the program! But we have to start
somewhere, don't we. The point is, the OP didn't post the code that has
the problem...
Aug 3 '08 #5
Daniel T. wrote:
Rajib <ra*****@verizon.netwrote:
>Daniel T. wrote:
>>"saneman" <as***@asd.comwrote:

I have made the following code:

std::vector<intv;
std::vector<int>::iterator it;
v.push_back(0);
v.push_back(0);
v.push_back(0);
v.push_back(1);
v.push_back(1);
v.push_back(1);
it = v.begin();
while (it != v.end()) {
std::cout << *it << std::endl;
it++;
}

It compiles fine (using MS VS 2008) and when I run it it also
prints 0 0 0 1 1 1. But then I get:

Debug Error!

Invalid allocation size 492.....bytes
and I need to pres either abort, try again or ignore. Is this a
windows specific issue?
What is the code that comes after this block?
It could also be code before that block that is causing the problem.

:-) It could be code half-way across the program! But we have to start
somewhere, don't we. The point is, the OP didn't post the code that has
the problem...
Yup, I'm just making sure the OP didn't have the idea that because the
debug error showed up after the output the mistake must have also
occurred after that piece of code.
Aug 3 '08 #6

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

Similar topics

0
by: CoolPint | last post by:
I am trying to write a generic heapsort (of course as a self-exercise) with Iterator interface: something like blow.... But I got into trouble finding out the Iterator to the Child node. If...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
16
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid...
6
by: RishiD | last post by:
Hi, I am using an iterator on a list, I wanted to know is there a simple way to erase() the current element the iterator is pointing to and move the iterator forward one? The only way I can...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
1
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party...
4
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
5
by: Luis Zarrabeitia | last post by:
Hi there. For most use cases I think about, the iterator protocol is more than enough. However, on a few cases, I've needed some ugly hacks. Ex 1: a = iter() # assume you got the iterator...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.