Vectors

What I'm trying to do is create a vector that will hold a message. So by using cin I am trying to store numerous characters into my vector without any limits. What I can't seem to do is store the information from the cin into the vector continuously. What I need to have is to be able to type - without interruption - and then for that text to be stored in the vector.

Help??

Thanks.
How about
1
2
std::string s;
std::getline(std::cin,s);
I was going to that, but I want to be able to access the string and be able to rearrange the items. Is it possible to convert a string into an array of char?
string provides operator[] which allows you to access the contents as if it
were an array of chars.

You could do something like this:

1
2
3
4
5
6
7
8
vector<string>words;
string temp=" ";
while(cin>>temp)//temp are the words that go into the vector words, each being a vector element
words.push_back(temp)//keep typing/adding words
if(temp=="no_more")break;//stop further input
sort(words.begin(),words.end())//sort the words in the vector from lowest to highest value
for(int i=0;i<words.size()-1;++i)//print the words - one to a line.
cout<<words[i]<<endl;

rgds hth`s
Have you seen this yet? If not, read it. You can do all kinds of things with the string class. The string is a class that encapsulates an array of characters. You can use its member functions to manipulate the data or get random access iterators to the characters. You can also pass the iterators to std algorithm methods such as std::count, std::find, std::reverse, etc.
http://cplusplus.com/reference/string/string/
Topic archived. No new replies allowed.