samedi 25 avril 2015

C++: looping over a string - iterator?

Let us assume I have different functions accessing a single String str (getting a single character of it) and I want to loop through this string with every access...how could I achieve this?

For example:

string str = "abc";
function1(); // returns "a"
function2(); // returns "b"
function3(); // returns "c"
function4(); // returns "a" again
function2(); // returns "b" again
...

So basically I have different functions accessing this string str and I need some kind of iterator which gets back to the first character of str if the end of str is reached.

Aucun commentaire:

Enregistrer un commentaire