0

I have a lab assignment where I have to get data from a file and separate the party id meal cost, how many adults or kids are in the party, if it is a weekend when they bought the meal and the total bill. This is what the data file contains.

1 10  0 S Y 100.00 
2 27 3 D Y 57.50 
3 125 17 D N 0.00 
4 4 0 S N 25.00 
5 0  25 S Y 23.75 
6 250 43 D N 500.00 
7 0 0 D N 0.0 
8 10 0 R Y 10.00 
9 17 3 D R 15.00 
10 5 0 D Y 275.00 
11 -3 10 D Y 20.00 
12 14 -1 S N 30.00 
13 20 3 D Y -10.00 

I know how to get input from the file but I don't know how to separate all this data to different int variables and bool and what not.

I tried making int variables and getting the file to input data into the variables but it would just copy what is on the file into the variables.

Retired Ninja
  • 4,785
  • 3
  • 25
  • 35
  • A simple way that assumes the file is well-formed is to define a variable of the appropriate type for each field and use `>>` to read into each of them from the file. For cases like the weekend you'd probably want to read into a temporary char variable and then use some logic to convert that to a bool. You could also read line by line with `getline` and then use a `stringstream` to split things up. You could search for how to split text based on spaces or how to read a CSV file knowing your separator is a space and not a comma. – Retired Ninja Nov 04 '22 at 04:47
  • 1
    [Example of above](https://stackoverflow.com/a/7868998/4581301). – user4581301 Nov 04 '22 at 05:18

0 Answers0