I'm writing a program for an assignment. It is a stationary kiosk where the user can select designs of stationaries and when they are done ordering it prints an invoice to the screen. The problem I'm having is that the program runs fine the first time but on the second iteration of the loop, when it hits the getline() function it sends ifstream into the failstate and the style variable is "NULL". The sheetsOrdered and envelopesOrdered variables then hold the same variables. Why is ifstream going into the fail state?
After the first getline(), it takes the entire line and also removes the \n for you.
Next, it reads the 3, but does not discard the \n. On the next read, >> discards the leading \n then reads the 3, again not discarding the trailing \n. After that, on your next loop, getline() immediately sees a \n and sees that as the entire like, returning "" and discarding it. Therefore on the next read of an int using >>, it sees "style name2" which is not valid for a int, which puts it into an error state.