0
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<char> a(n);
    copy(istream_iterator<char>(cin),istream_iterator<char>(),a.begin());
    copy(a.begin(),a.end(),ostream_iterator<char>(cout," "));    
    return 0; 
}

in the 7th line, to stop the istream_iterator needs to be stopped explicitly by pressing Ctrl + z

Else the istream_iterator continues to expect input and it is stuck there until the user presses Ctrl + Z and then the rest of code is executed

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 4
    Sitenote: [Why should I not `#include `?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Ted Lyngmo Jul 11 '20 at 14:20
  • Is this question still unanswered? I ask because I thought I answered it. Ask if it's not clear please. – Ted Lyngmo Jul 24 '20 at 02:32

1 Answers1

0

No, and in your case that would be wrong. If you stop at a newline, the user may have entered more than n chars and then you have undefined behavior since you would write out-of-bounds.

You need copy_n:

copy_n(istream_iterator<char>(cin), n, a.begin());
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108