Use the following pieces of code and write the msising statements (2) that creat
ID: 3601670 • Letter: U
Question
Use the following pieces of code and write the msising statements (2) that create the input and output iterators for this program.
cout << "Enter two integers: ";
//create istream_iterator for reading int values from cin - name of iterator is inputInt
MISSING STATEMENT 1 // PLEASE CODE THIS STATEMENT
int number1{*inputInt}; // read int from standard input
++inputInt; // move iterator to next input value
int number2{*intputInt}; // read int from standard input
// create ostream_iterator for writing int values to cout - name of iterator is outputInt
MISSING STATEMENT 2 // PLEASE CODE THIS STATEMENT
cout << "The sum is: ";
*outputInt = number1 + number2; //output result to cout
cout << endl;
Explanation / Answer
Please find my answer.
cout << "Enter two integers: ";
//create istream_iterator for reading int values from cin - name of iterator is inputInt]
std::istream_iterator<int> inputInt (std::cin);
int number1{*inputInt}; // read int from standard input
++inputInt; // move iterator to next input value
int number2{*intputInt}; // read int from standard input
// create ostream_iterator for writing int values to cout - name of iterator is outputInt
std::ostream_iterator<int> outputInt (std::cout);
cout << "The sum is: ";
*outputInt = number1 + number2; //output result to cout
cout << endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.