LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2006, 10:32 AM   #1
aral
Member
 
Registered: Aug 2005
Posts: 115

Rep: Reputation: 15
c++/going through vector ends program


Why does the following code stop after the display of just one "1st for" message ?, so I guess it doesn't even get into that first if ... When I say it stops I mean the process stops with exit value -1. I guess there should be no elements in the vector when it enters in that first for , but why does it stop after exactly one :"1st for" message ?
Do I have to catch any exceptions for std::vector ?
Code:
   
std::vector<KeepAliveMsg> vec;
std::vector<KeepAliveMsg>::iterator p;
for(p=vec.begin();p != vec.end();p++)
{   //a=(*p).pid;
    //b=ob.get_qbuf().pid;
std::cout<<i++<<"."<<" 1st for"<<std::endl;
if( ( (*p).pid)==ob.get_qbuf().pid )
{
std::cout<<i++<<"."<<"wdog before timestamp update"<<std::endl;
(*p).timestamp=ob.get_qbuf().timestamp;
timestamp_changed=true;
}
}//for

if(!timestamp_changed)
		  			{
		  				std::cout<<i++<<"."<<" wdog before push_back in vec"<<std::endl;
						vec.push_back(ob.get_qbuf());
						std::cout<<i++<<"."<<"wdo after push_back in vec"<<std::endl;
						if ( vec.size() != 0 )
							   std::cout<<"Last element: "<<vec.back().pid<<std::endl;
		  			}

Last edited by aral; 10-14-2006 at 01:21 PM.
 
Old 10-11-2006, 11:34 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
how about some code tags..
 
Old 10-14-2006, 07:53 AM   #3
aral
Member
 
Registered: Aug 2005
Posts: 115

Original Poster
Rep: Reputation: 15
So how do I put those ?
 
Old 10-14-2006, 10:08 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
[code]
your code goes in here
[/code]
 
Old 10-16-2006, 12:34 PM   #5
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
The code, as you've posted it, shouldn't even loop once. The default constructed vector<KeepAliveMsg> vec is empty so vec.begin()==vec.end(). Hence no loop.

Try and produce the smallest piece of code you can that runs independently (ie we can paste it, compile it, and run it) and produces the error.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
program name ends in question mark objectiveal Programming 5 05-11-2006 03:40 AM
LXer: Synfig 2D vector animation program opens source LXer Syndicated Linux News 0 01-24-2006 02:16 PM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM
Miseries at install from HDD&floppies, with vector ISO& how to boot with vector linux prctom VectorLinux 9 06-29-2004 05:27 AM
Vector Graphics Program Needed guygriffiths Linux - Software 0 11-26-2003 05:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration