Converting from allocator to vector

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
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?
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
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
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.
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.