CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Posts
    18

    How to terminate cin?

    I use
    Code:
    vector<string> Names;
    copy(istream_iterator<string>(cin), istream_iterator<string>(),back_inserter(Names));
    ....other code...
    to read strings from cin stream.
    The problem is I don't know how to terminate the input stream and run the code below it. I tried Enter,"Ctrl+D"...but the screen remain the status of receiving the input...

  2. #2
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Re: How to terminate cin?

    The default constructor of istream_iterator constructs an iterator that represents past-the-end. The first iterator will only be equal to the past-the-end one (and therefore input will only terminate) if something causes the eofbit or failbit of the stream passed as an argument (in your case, cin), to be set. So one way of terminating input is simulating the end-of-file character from the keyboard, usually done with Ctrl+Z.

    I'm not sure if you have any choice other than a default-constructed istream_iterator object as the second argument to copy() in a case like this.
    Old Unix programmers never die, they just mv to /dev/null

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured