2. Second Project
This program will read eight numbers from a text file, it
will then ask the user how many containers will be on
the ship and then determine if the ship is safe or
whether it is to heavy.
3. Declaring and opening file
Firstly a text file needs to be
created in the same source file as
the C++ code. As you can see to
the left I made a text file called
input.txt
This code declares the file as a
variable. Then it opens the file so the
project can access its context.
4. Inside the text file
This is what is inside the text file. Each
number represents a variable and is the
variable is given that value
5. How to read in from a file
It acts in the same way as the CIN function where the
file(variable) gives cargo1 the first value which is inside the
input.txt file.
6. Result
This shows that the length, width and height of the cargo is
automatically assigned and there is no need for any user input.