Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

quick question

Name: Anonymous 2007-05-04 15:05 ID:E3M9p2QX

C++.

I have an array of strings.
I want to read into this from cin until there is nothing left in the buffer.

i.e. input = "hello my name is anon"

i want the equivalent of

for(int i = 0; i < 5; i++)
    cin >> arrayName[i];

for any number of words

is there some sort of flag i can use?

Name: Anonymous 2007-05-07 2:34 ID:6xJq2jpV

>>14
>>1
Except that it needs moar work or the OP's stuff will need you to type CTRL-D twice, if using this code:

#include <vector>
#include <string.h>
#include <iostream>
#include <iterator>
using namespace std;


int main()
{

  vector<string> poo;
  copy(istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(poo));

  int len = poo.size();
  int i = 0;
  cout << endl;

  while(i < len)
    {
      cout << i << ": " << poo[i] << "\n";
      i++;
    }

}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List