Good Evening everyone, long time lurker, first time poster. I have an issue trying to read information from a file that I'm struggling with. My function takes a file input object and reads information into arrays of type int, int, double, char (2 dimensional array). The file data looks like this:

512 43 10.19 chips

// global constant
const int MAX = 30;

//function header
void printStats( int a[], int b[], double c[], char d[][MAX], ostream&, ifstream& );

//function body
void printStats( int a[], int b[], double c[], char d[][MAX], ostream& dataOut, ifstream& fileIn )	{
	int count = 0;
	while ( !fileIn.eof() )	{
		fileIn >> a[count] >> b[count] >> c[count] >> d[count];

At this point, this function simply doesn't work and I don't think I'm understanding the 2-D array correctly. I tried using:

while ( !fileIn.eof() )	{
		fileIn >> a[count] >> b[count] >> c[count];
		fileIn.getline( d[count], MAX, '\n' );

but my character array ends up collecting the first integer on the newline...I was under the impression that as long as I passed a 2-D array a size for the number of columns, I could simply read data into it by passing d[count]......

I left the majority of my code out of this post to keep things simple, so I hope I've given a clear idea of the situation.

6 Years
Discussion Span
Last Post by WaltP
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.