What is the output?

May 21, 2018 at 4:26pm
Suppose that num is an int and discard is a char. Assume the following input data:#34
What value (if any) is assigned to num and discard after each of the following statements executes? (Use same input for each statement.)
So I assume this code results in input failure?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int num;
	char discard;

	cin.get(discard);
	cin >> num;


	discard = cin.peek();
	cin >> num;

	cin.get(discard);
	cin.putback(discard);
	cin >> discard;
	cin >> num;


    return 0;
}

Last edited on May 24, 2018 at 3:58am
May 21, 2018 at 4:43pm
Why don't you just run the program and see for yourself?
May 21, 2018 at 5:06pm
Don't just dump your assignment.
What is your question?

And remember to use code tags when posting code: http://www.cplusplus.com/forum/articles/16853/
Topic archived. No new replies allowed.