Placing element of string into vector

I am not sure why I am getting an error for this:

void create_list(const string & str_text, vector<char> & vec_text)
{

for (int i = 0; i < str_text.size(); i++)
{
if (is_alphabetic(str_text[i]) ==true)
{
vec_text[i] = str_text[i];
}

}
}

I am not sure how to place an element of a string inside a vector using loops.
As your code is currently, vec_text has to be the same size as the string for your function to work as intended. Are you sure you don't want to use .push_back()?
http://www.cplusplus.com/reference/vector/vector/push_back/
http://en.cppreference.com/w/cpp/container/vector/push_back
You need to use the vector class push_back function to add new elements to the vector.

So something like this:
 
vec_text.push_back( str_text[i] );

http://www.cplusplus.com/reference/vector/vector/push_back/
Yep that was the problem Thank you
Topic archived. No new replies allowed.