Connecting Tech Pros Worldwide Forums | Help | Site Map

Simple iterator problem

saneman
Guest
 
Posts: n/a
#1: Aug 2 '08
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?



kwikius
Guest
 
Posts: n/a
#2: Aug 2 '08

re: Simple iterator problem



"saneman" <asdff@asd.comwrote in message
news:489486d6$0$90272$14726298@news.sunsite.dk...
Quote:
>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++;
}
}




Daniel T.
Guest
 
Posts: n/a
#3: Aug 3 '08

re: Simple iterator problem


"saneman" <asdff@asd.comwrote:
Quote:
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?
Rajib
Guest
 
Posts: n/a
#4: Aug 3 '08

re: Simple iterator problem


Daniel T. wrote:
Quote:
"saneman" <asdff@asd.comwrote:
>
Quote:
>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.
Daniel T.
Guest
 
Posts: n/a
#5: Aug 3 '08

re: Simple iterator problem


Rajib <rajibeq@verizon.netwrote:
Quote:
Daniel T. wrote:
Quote:
"saneman" <asdff@asd.comwrote:
Quote:
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...
Rajib
Guest
 
Posts: n/a
#6: Aug 3 '08

re: Simple iterator problem


Daniel T. wrote:
Quote:
Rajib <rajibeq@verizon.netwrote:
Quote:
>Daniel T. wrote:
Quote:
>>"saneman" <asdff@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.
Closed Thread