I am reading a book of C ++ programming languages ββand went to βIterators and I / Oβ on page 61, they give the following example to demonstrate repetition through the line presented.
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
istream_iterator<string>ii(cin);
istream_iterator<string>eos;
string s1 = *ii;
++ii;
string s2 = *ii;
cout <<s1 << ' '<< s2 <<'\n';
}
What I fully understand, now I played with this example to make it work for numbers as well. I tried to add the following in appropriate places ...
istream_iterator<int>jj(cin);
int i1 = *jj;
cout <<s1 << ''<< s2 << ''<< i1 <<'\n';
Which does not give me the opportunity to enter the number section when starting the program. Why is this so? Is it possible to use an iterator only once per cin? such that it already has input from cin, so the next iterator is ignored?
Change this is what I got after pasting
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
istream_iterator<string>ii(cin);
istream_iterator<string>eos;
string s1 = *ii;
++ii;
string s2 = *ii;
int d =24;
cout <<s1 << ' '<<s2<<' '<<d<< '\n';
}
Above work for
Hello world or
hello
world
Hello World .
istream_iterator<int>dd(cin);
int d = *dd;
int d =24;
Hello Hello 0.