473,785 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning all locations of a specific repeated element in a vector/deque

2 New Member
Dear All,

I am trying to use the STL-'find' function to find all the locations of a specific repeating element in an unsorted vector/deque. I want the original vector/deque to stay unsorted. It is my understanding from the text books that 'find' will only return the location of the first occurence of the element in question. Is there an existing STL function that I can use?

Any suggestions would be greatly be appreciated.

Cheers
Ernst
Jan 31 '08 #1
3 1656
gpraghuram
1,275 Recognized Expert Top Contributor
Dear All,

I am trying to use the STL-'find' function to find all the locations of a specific repeating element in an unsorted vector/deque. I want the original vector/deque to stay unsorted. It is my understanding from the text books that 'find' will only return the location of the first occurence of the element in question. Is there an existing STL function that I can use?

Any suggestions would be greatly be appreciated.

Cheers
Ernst
I dont think so that a function which suits your requirement exists.
My idea is you can use an iterator to traverse the vector/deque and then store all the matched positions tiil you reach the end of the vector/deque

Raghuram
Feb 1 '08 #2
escholtz
2 New Member
I dont think so that a function which suits your requirement exists.
My idea is you can use an iterator to traverse the vector/deque and then store all the matched positions tiil you reach the end of the vector/deque

Raghuram
Thanks Raghuram. That is what I suspected.
Feb 1 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
It is my understanding from the text books that 'find' will only return the location of the first occurence
That's true. But it uses an iterator as the starting location. You can use the iterator from the first location to be the start point for the next find. Just advance it by 1.
Feb 1 '08 #4

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

Similar topics

2
29522
by: tornado | last post by:
hi all, i am pretty new to c++. i have this problem for which i am unable to think a solution. i don't understand how to pass a vector refernce back to the callin function. And how this reference will be handled by the calling function ? Can any one in the group point me to the correct solution for it ? Any code snippets will be of great help. Thanks in advance.
7
4461
by: jose luis fernandez diaz | last post by:
Hi, Is this right any stl container (vector, deque, list, . . .)? typedef vector container; int main() { container<int> c1;
7
12631
by: William Payne | last post by:
(This post is related to "recent files menu"-post below. If I should have kept this in that thread, I apologise.) Hello, I have a function that adds a std::string to a std::vector. New entries are added at the front (index 0) of the vector. If the vector contains a certain amount of elements, the element at the back is removed when a new one is added. If one tries to add a string already stored in the vector, that string is supposed to...
34
4176
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and "push_back" a copy of this into a vector V. This is repeated many times in an iterative process. Ok whenever I "push_back" a copy of Class A, I also want to assign a pointer contained in an exisiting instance of a Class B to this
5
3034
by: Adam Hartshorne | last post by:
Hi All, I want to set a pointer to the penultimate element in a std::list, what is the best way of doing this? Also would setting a pointer to the end of the list, and then adding another element, also result in a valid pointer to the then penultimate element of the the list? (i.e. achieving basically the same thing) I ask this because I know there is problems with setting pointers with std::vector then adding elements to the vector....
2
1605
by: cuneyt | last post by:
Hi all: I have defined the template template<class T> class CGroup private: int nSize; public: std::deque<T> c;
5
6159
by: yancheng.cheok | last post by:
after reading http://www.codeproject.com/vcpp/stl/vector_vs_deque.asp, i realize that deque has its own speed advantage over vector in all the aspect (except for memory deallocation). does it mean that we should prefer deque over vector? (in contrast with c++ standard, which recommence vector over deque) thanks!
32
4040
by: T. Crane | last post by:
Hi, I'm struggling with how to initialize a vector<vector<double>> object. I'm pulling data out of a file and storing it in the vector<vector<double>object. Because any given file will have a large amount of data, that I read off using an ifstream object, I don't want to use the push_back method because this grows the vector<vector<double>dynamically, and that will kill my execution time. So, I want to reserve space first, using, of...
16
2070
by: subramanian100in | last post by:
Program 1: --------------- #include <cstdlib> #include <iostream> #include <vector> using namespace std; int main() {
1
10083
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,...
0
9946
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, 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...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.