1

Hi everyone..i'm new c++ programming and i would like to know if its posible to convert a string to a vector array...(Eg string s = "Hello everyone" array a[1]='H', a[2]='e'....)I need a vector array because i do not know what my string will be...it will change everytime...If it is posible i would please like to know the solution...

3
Contributors
4
Replies
6
Views
11 Years
Discussion Span
Last Post by ~s.o.s~
0

why not just index into the string? You don't need a vector just to get a character from the string object.

std::string s = "Hello World";

for(size_t i = 0; i < s.length(); i++)
{
   char c = s[i];
   cout << c << "\n";
}

If you really really want to make it a vector, just do puch_back on the vector instead of cout in the above code.

0

Thanks a lot mate...this really helped me out :D...however for the sake of knowing, how do i use the push_back??i tried

push_back << c << "\n";

didn't work..:(

0

piush_back is a method of the vector class --

vector<char> array;

array.push_back('A');

All c++ text books have examples of vector class and how to use them. You should read it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.