473,480 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to delete a value from a vector

nabh4u
62 New Member
hi,
i have a program where i have some values stored in a vector. when i add a new value to the vector i want to delete a specific value from the vector. how can i do that. what is the syntax for deleting an element in a vector. i tried on google but i couldnt find d exact answer.
please help.
Feb 2 '07 #1
4 4526
rajesh6695
96 New Member
hi,
i have a program where i have some values stored in a vector. when i add a new value to the vector i want to delete a specific value from the vector. how can i do that. what is the syntax for deleting an element in a vector. i tried on google but i couldnt find d exact answer.
please help.
are you speaking about argument vector or what vector? Please Explain littile bit
Feb 2 '07 #2
horace1
1,510 Recognized Expert Top Contributor
hi,
i have a program where i have some values stored in a vector. when i add a new value to the vector i want to delete a specific value from the vector. how can i do that. what is the syntax for deleting an element in a vector. i tried on google but i couldnt find d exact answer.
please help.
have a look at erase() in <vector>
http://www.cppreference.com/cppvector/index.html
Feb 2 '07 #3
nabh4u
62 New Member
have a look at erase() in <vector>
http://www.cppreference.com/cppvector/index.html
if u want to remove the value whose index value you dont know then how do you remove that value from the vector?

to use erase, we need to use iterators and we need the exact location of the element to be deleted. how do we get the exact location of the element we want to delete in a vector.
Feb 2 '07 #4
RedSon
5,000 Recognized Expert Expert
You do exaclty what you say. Iterate through the elements. Start at the first one and see if it mathces the data you want to delete. If it doesnt move on to the next one. Try it out yourself, if you are having problem with the code, post your code here (inside some code blocks) so we can have a look at it and see how we can help you.
Feb 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
9774
by: Hitesh Bhatiya | last post by:
Hi all, I have written a small program to accept some socket connections, which are then added to a vector (using push_back). But after a few calls to the push_back function, it deleted the...
16
1992
by: cppaddict | last post by:
Hi, I am deleting some objects created by new in my class destructor, and it is causing my application to error at runtime. The code below compiles ok, and also runs fine if I remove the body...
5
2461
by: Alexander Stippler | last post by:
Hello, I have got a list of indices stored as a stl::vector and a range given by two iterators, lets say . The values in this range are not ordered, but I have another range of values, lets say...
9
3589
by: david wolf | last post by:
I want to delete all even numbers in a vector, I am not sure if there's any better way to do it. Following program is how I did it. Look at the part of code beginning from comments: //delete all...
35
2585
by: Jon Slaughter | last post by:
I'm having a problem allocating some elements of a vector then deleting them. Basicaly I have something like this: class base { private: std::vector<object> V;
10
3197
by: Whybother | last post by:
I have this typedef map<__int64, int> Results_Map; __int64 is defined as 8 bytes ranging from -9,223,372,036.854,775,808 to 9,223,372,036.854,775,807 I have loaded it with approx 34 million...
7
4319
by: JH Programmer | last post by:
Hi, is there any ways that allow us to delete an element in between? say int_val: 1 int_val: 2 int_val: 3
19
10722
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
9
1785
by: Oliver Graeser | last post by:
Hi All, I do some ensemble averaging calculation that requires me to accumulate very many distributions which I store in arrays. Basically something like class AdaptiveNW{ public: int**...
0
7037
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,...
0
6904
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...
0
7032
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,...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6873
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...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2990
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...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
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 ...

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.