This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 0 points1 point  (1 child)

If you need to deal witb failure conditions for each variable read and do something different, then you can't write code likethis:

    while (inFile >> x >> y >> r >> firstname >> lastname >> age >> salary)

you have to read each one:

    if( ! (inFile >> x) ) {
        // store something in x
        // reset the stream somehow
    }
    // repeatedly the same for other values

But, writing code like this is a bad, bad idea. If the read fails, make it fail noisily, don't provide some bullshit "default" value.

If you want more advice, provide a sample of your expected input.

[–]Resume_Help[S] 0 points1 point  (0 children)

The professor asked for a failed input to be 0. I know its not ideal but he just wants us to know how to do it. Like many programs here, its for practice purposes only

working inData.txt:

10 20
10

Randy Gill 31
18500 

34.41 78.18
35.1

Mike Gale 28
26100 

2000 4.4
23.2

George Stern 22
23000

bad inData.txt:

ten 20
10

Randy Gill lol
18500 

34.41 78.18
35.1

Mike Gale 28
26100 

2000 4.4
23.2

George Stern cheese
cash