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.
4 4533
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
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.cppreferenc e.com/cppvector/index.html
have a look at erase() in <vector>
http://www.cppreferenc e.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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 object that was added last.
Could someone please tell me why this happens ? Am I doing something wrong
here ?
|
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 of the
destructor. So I think I am somehow using delete incorrectly, but I'm
not sure exaclty what I'm doing wrong.
I'd apprecitate any clarification and suggestions for rewriting the
below properly.
|
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 lower to upper. Now I
want to remove all values from the stl vector in range having
values in . I have just tried around with remove_if and some
predicates, but I'm not used to the algorithms library. Perhaps someone can
help me.
|
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 even numbers.
My questions is actullay I have to put pos++ in the body of the
loop(also in if, else, statement). Can I somehow put it in
for(...;...;...).
Or can I use index instead of iterator in order to delete elements from
|
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;
| |
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 hash keys and when the program is
shutting down it takes forever (10+ mins) while its deleting the objects.
The memory it uses according to task manager is varies from 500,000 k then
|
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
|
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
there an existing adapter?
Thanks,
Daniel.
|
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** getDegreeDistribution();
.......
}
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
| |