The basic concept of this code is that you take input from a .txt file about The type of operation you want to do, the first number and the second number (It's a calculator obviously). So if i write "Addition 2 3" It should output 5 to the output.txt file, but it prints some numbers and letters which i think its an address of some sort. how do i solve this? much thanks. This is the code (please don't mind that it's written in italian):
But wouldnt this get the value from the emulator? i need to get the num1 value and num2 value just from the text file; Imagine if i you write this in the "input.txt" file:
Addition
2
3
using infile>>scelta>>num1>>num2; i should save "Addition" on the string scelta, 2 on num1 and 3 on num2. But i think i'm doing something wrong with the string. Thanks for your help.
Thanks for your help everyone!
Ganado, why exactly do i put those while parameters? Whats the difference between putting those parameters on the while loop and using a while with !infile.eof() and with infile >> scelta >> num1 >> num2 inside?
Luca, you are slightly misquoting me: I said that you should put the [first] read statement in the while test. @Ganado's form is good here.
The problem with !infile.eof() is that this is NOT triggered by reading the last item, but by trying to read another one afterward. The end result is that a loop which shouldn't run actually does, the stream fails and what was previously in the input variable ends up being dealt with twice.