I want my program to read a data file (i.e myData.dat) that contains strings, integers and character. I'm problem is that i don't know how to read these different data types and output them in a different file. I don't know if i need to use three different while loops, each reading its own data type. please tell how to solve this one. thanking you in advance.
the following is the contents of the file i want my program to read.
Peter 3 / + - *
Dahne 8 + - / *
Renee 7 - * + /
Charl 1 * / + -
Johan 2 / - * +
Sipho 4 * - / +
I think you gave a good idea but i have a problem with the part where you read characters. Its seems like in one iteration your loop will read one string (i.e name), one integer, and one operator and then it jumbs to the next iteration. I want it to read all characters(i.e operators) before it moves on to the next line.
hi Moschops, your loop work perfectly fine but it reads Sipho 4 * - / + twice. is it because i used while(!infile.eof()) as my loop's condition. how can i solve this?
the cursor is at the begiunning of the file in my input file. so i don't think that the cursor is the problem. As far as i know the eof() function will allow the loop to perfom one more iteration after the loop has reached the end of file. I just wanna know how this can be avoided.
the cursor is at the begiunning of the file in my input file. so i don't think that the cursor is the problem.
The cursor is not the issue. It's just an indicator.
Ok, let me rephrase...
Do you have a blank line at the end of your file? A blank line is still not an eof. It's not an eof until it actually cannot read anymore. A blank line is any line w/o text after your text, even if the only space is the space the cursor sits.