C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 15th, 2009, 08:05 AM
clarky728 clarky728 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 10 clarky728 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 59 sec
Reputation Power: 0
Deleting what i want in vectors

in a vector i put in what it is i want.

like cust id 1001 reg AAA

ect up to 1005 and EEE.

how do i make it delete 1003 CCC from the vector.

code i have is this.


void Manager::showHires()
{
string reg;

system("cls");
cout << endl << "List of Hires" << endl << "==============" << endl;

vector <Hired>::iterator iter = theHired.begin();
for(iter = theHired.begin();iter != theHired.end();++iter)
{
if(!isHired(reg))
{
(*iter).getDescription();
cout << endl;
}
}
}


void Manager::returnHire()
{
bool custfound = false;
bool carfound = false;
int id;
cout << "Enter Customer ID: ";
cin >> id;

if(findCustomer(id))
{
custfound = true;
}

string reg;
cout << "Enter CarRegno: ";
cin >> reg;

if(findVehicle(reg))
{
carfound = true;
}

if(custfound == false)
{
cout << "CustomerID not found!" << endl;
}

if(carfound == false)
{
cout << "Car RegNo not found!" << endl;
}
else
{
if(isHired(reg))
{
cout << "Car was hired and has now been set to AVAILABLE!" << endl;
setHired(reg,false);

Hired h(id,reg);
theHired.erase_element(h);
}
else
{
cout << "Car has already been returned!" << endl;
}
}
}
void Manager::createHire()
{
bool custfound = false;
bool carfound = false;
int id;
cout << "Enter Customer ID: ";
cin >> id;

if(findCustomer(id))
{
custfound = true;
}

string reg;
cout << "Enter CarRegno: ";
cin >> reg;

if(findVehicle(reg))
{
carfound = true;
}

if(custfound == false)
{
cout << "CustomerID not found!" << endl;
}

if(carfound == false)
{
cout << "Car RegNo not found!" << endl;
}
else
{
if(!isHired(reg))
{
cout << "Car is available and has been set to HIRED!" << endl;
setHired(reg,true);

Hired h(id,reg);
theHired.push_back(h);
}
else
{
cout << "Car is NOT available!" << endl;
}
}
}


trying to make it when i return the car it deletes what i put in and still shows the rest as they are still hired.

and help would be gratful

Reply With Quote
  #2  
Old May 15th, 2009, 09:36 AM
tinit5190 tinit5190 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 57 tinit5190 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 31 m 46 sec
Reputation Power: 2
Don't know if this will apply to your problem, but there is a member function common to what you want to do. that is:
Code:
vectorName.erase(position)


This code deletes the element at the position specified by the iterator.

Reply With Quote
  #3  
Old May 19th, 2009, 06:22 AM
clarky728 clarky728 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 10 clarky728 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 59 sec
Reputation Power: 0
everytime i try this bit of code i get an error.

the program adds hires in through the vector but it's not always the last or first hire that gets returned so i tryed

Hired h(id,reg);
theHired.erase(h);

hoping that after i have put the details in of the car im returning the erase might take it out,

anyone got other idea's???

Reply With Quote
  #4  
Old May 28th, 2009, 08:59 AM
MaHuJa MaHuJa is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2007
Posts: 880 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 Days 19 h 48 m 25 sec
Reputation Power: 2
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
Quote:
Originally Posted by clarky728
Hired h(id,reg);
theHired.erase(h);


Hired h(id,reg);
theHired.erase(theHired.find(h));

If you know its offset into the vector, do something like

theHired.erase(theHired.begin()+3); // erase the 3rd element
__________________
Quote:
Programming by Coincidence
Fred types in some more code, tries it, and it still seems to work. [Then] the program suddenly stops working. [...] Fred doesn’t know why the code is failing because he didn’t know why it worked in the first place.

Reply With Quote
  #5  
Old May 29th, 2009, 04:34 AM
clarky728 clarky728 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 10 clarky728 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 59 sec
Reputation Power: 0
there is no such thing as a .find in a vector.

when i tryed it i got errors and when i looked up what goes with vectors it was not in it.

i tryed doing this instead

Hired h(id,reg);
theHired.erase(theHired.at(h));

but i get this error

error C2664: 'const Hired &std::vector<_Ty>::at(unsigned int) const' : cannot convert parameter 1 from 'Hired' to 'unsigned int'
1> with
1> [
1> _Ty=Hired
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Reply With Quote
  #6  
Old May 29th, 2009, 08:31 AM
MaHuJa MaHuJa is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2007
Posts: 880 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 Days 19 h 48 m 25 sec
Reputation Power: 2
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
Quote:
Originally Posted by clarky728
there is no such thing as a .find in a vector.


Oops.

Code:
#include <vector>
using std::vector;
#include <algorithm>
using std::find;

int main() {
  vector<int> v;
  // fill v
  int value = 5; // first to compare equal is removed
  v.erase(find(v.begin(), v.end(), value));
}

Reply With Quote
  #7  
Old July 2nd, 2009, 10:33 AM
larssss larssss is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 30 larssss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 54 m 18 sec
Reputation Power: 1
You could say :
Code:
 #include <vector>
using std::vector;
#include <algorithm>
using std::find;

int main() {
  vector<int> v;
  // fill v
  v[0] = 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Deleting what i want in vectors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek