Converting from allocator to vector

Dec 30, 2011 at 6:49pm
Hello, i´m new to this forum and looking for a little bit of help if I may.

How can I convert a std::allocator<std::string to a std::vector<std::string and still be able to iterate through every character of the std::allocator<std::string ?

thanks
Last edited on Dec 30, 2011 at 6:50pm
Dec 31, 2011 at 3:53pm
Why do you want to use std::allocator for? Do you intend to develop your own container?

I know that you can create an iterator of vector<string> container simply by
vector<string>::iterator iter;

Define a vector<string> container:
vector<string> vec;

And initialize it:
iter = vec.begin();

Then you can loop through each element by incrementing iter (iter++ for example) and get each elements contents by dereferencing this iterator:
string str = *(iter);

Is that what you want?
Jan 2, 2012 at 6:54pm
I want to create a string, take input from the user, then be able to iterate through each character and for every four characters create a value of a vector<string> by using push_back
Jan 2, 2012 at 8:55pm
Do you need to use an actual iterator? Your problem description makes me think of substr(), which would work more easily with indices.
Last edited on Jan 2, 2012 at 8:56pm
Jan 3, 2012 at 8:28am
no i do not need to use an actual vector<string>::iterator, I just want to iterate through the characters with [] and the position number inside the square bracket.
Jan 4, 2012 at 9:16pm
Well, then it should be easy enough to do!

string::operator[] + vector::push_back() + string::substr() + some sort of loop

Have you given it a go?
Topic archived. No new replies allowed.