My professor is very smart but expects complete noobs like me to just know how to program c++. I don't understand how the fstream
function works.
I will have a data file with three columns of data. I will have to determine with a logarithm whether each line of data represents a circle, rectangle or triangle - that part is easy. The part I don't understand is how the fstream
function works.
I think I:
#include < fstream >
then I should declare my file object?
ifstream Holes;
then I open it:
ifstream.open Holes; // ?
I don't know what the proper syntax is and I can't find straightforward tutorial. Everything seems way more advanced than my skills can handle.
Also, once I've read-in the data file what is the proper syntax to put the data into arrays?
Would I just declare an array e.g. T[N]
and cin
the fstream
object Holes
into it?
Let me step through each part of reading the file.
Please note that this example doesn't deal with error detection.
Basic
ifstream
usage:Let's go further and assume we want to process each line according to some pattern. We use string streams for that: