Get Next element of a Set etc...

Oct 15, 2008 at 1:51am
Hi im a newbe to C++ and need some help off some of u pros lol...

Right basically I've a Set and need to get access to the next element, probobly using some sort of iterator or changing my set to some other object that supports the getNext()/next() method...

i.e. I've set is called irishDic, it contains words in irish, and their english translation in the immediate posisition next to the irish word, then i want to insert the next element into an other set called englishText was trying stuff like this...

if (irishDic.count(word) != 0)
//then i wont to be able to do something like
englishText.insert(irishDic.next());

With no luck at all ;-(
And got a sore head when trying to think of using an Iterator, so hopefully someone cant help

Regards

Pat Nevin
Oct 15, 2008 at 5:06am
Actually, I would think a better idea would to put them into a vector of pairs.

However, for this, I would just use an iterator...I will give you an example:

1
2
3
4
5
6
7
8
//sort of pseudocode
for(list<string>::iterator i = irishDic.begin(); i != irishDic.end(); ++i) {
//list<string>::iterator is an iterator for a list of strings
//irishDic.begin() sets i to be the beginning of the list
//i != irishDic.end() is what i will be when it is at the end of the list
//++i iterators work with ++ += etc...
//then inside of this loop you will have each line, you can basically do whatever you want
}
Oct 15, 2008 at 12:19pm
Hi and thanks for that, used vector<string>::iterator and the at() method and it did exactly what i wanted it to do.... so thanks agian
Last edited on Oct 15, 2008 at 12:53pm
Oct 15, 2008 at 6:11pm
No problem.
Topic archived. No new replies allowed.