473,414 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

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 1630
gpraghuram
1,275 Expert 1GB
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
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 Expert Mod 8TB
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
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...
7
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
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...
34
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...
5
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...
2
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
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...
32
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...
16
by: subramanian100in | last post by:
Program 1: --------------- #include <cstdlib> #include <iostream> #include <vector> using namespace std; int main() {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
jinu1996
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...
0
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
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
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...

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.