I am trying to infile my data file into two seperate arrays which are seperated by a white space in my file.
But I keep getting -86******* something number where my file is suppose to be any help will be very helpful. My first array which will read the student id is a one dimensional array and the second arry is a 2 dimensional arry which will read in the students answers to a true false test and the second col will be the total number correct for each true false question. Yeah and the answer key is suppose to be the last line in the 2 D array which is the first line in my data file.

#include<iostream>
#include <fstream>
#include "string"
using namespace std;
int main()
{
    const int maxstudents=50;
	const int maxcols=3;
	char quiz[maxstudents+1][maxcols];
    int studentid[maxstudents];

	ifstream infile;
    string inputfile;
	cout<<"Input filename"<<endl;
	cin>> inputfile;
	
	infile.open(inputfile.c_str());
	for (int c = 0; c<maxstudents; c++)
		infile>>quiz[maxstudents][c]; 
		for (int k=0; k<maxstudents; k++)
			infile>>studentid[k];
			
		    for (int j=0; j<maxstudents; j++)
				cout<<"studentid"<<j<<"\t"<<studentid[j]<<endl;
              for (int r=0; r<10; r++)
	         cout<<quiz[maxstudents][r]<<"\t";
           

return 0;
}

post the contents of the data file, or just a few lines if its too large. Your program is written to expect all student ids to be listed first, followed by all answers and lastly the total number correct for each student. But I doubt that is how they appear in the data file.

This is a piece of the data file.

tttttttfft
3685 ttftttttft
2525 ttftfffttt
3689 ttfffftttt
3644 fftttffttt
2505 fffffttttt
2523 tttttttttf
1254 tttttttttt
5255 fffffffftt

where is the third column? Your program needs only one loop. maxcols is too small -- needs to be 1 more than the number of t/f test scores.

for (int c = 0; c<maxstudents; c++)
{
	infile>>studentid[c] >> quiz[c]; 
}

i tried that and still got the -86 error

-86, is that a compile-time error or runtime error?
1. make sure maxstudents is not greater than the number of lines in the data file. There are better (and easier) ways to read the file without knowing the number of lines beforehand, but get this working first and you can refine your program later.

2. The output line is incorrect. It should look like this:

cout<<quiz[r]<<"\t";

If you still have problems after making the changes, repost your program. But those should fix it, at least it did in my version that I don't intend to post :)

#include<iostream>
#include <fstream>
#include "string"

using namespace std;


 const int maxstudents=25;


int main()
{

    const int maxcols=4;
    char quiz[maxstudents+1][maxcols];
    int studentid[maxstudents];

    ifstream infile;
    string inputfile;
    cout<<"Input filename"<<endl;
    cin>> inputfile;

    infile.open(inputfile.c_str());


for (int c = 0; c<maxstudents; c++)
{
    infile>> studentid[c] >> quiz[c]; 
}

for (int r=0; r<maxstudents; r++)
      cout<<quiz[r]<<"\t";  
return 0;
}

const int maxcols=4;


Count the number of t's and f's in one of those lines. How many did you count? Less than 4 or more than 4. maxcols needs to be a minimum of (number of t's and f's) + 1 for the character array's null-terminator.

I am getting a blank page

#include<iostream>
#include <fstream>
#include "string"

using namespace std;


 const int maxstudents=3;
int main()
{


    ifstream infile;
    string inputfile;
    cout<<"Input filename"<<endl;
    cin>> inputfile;

    infile.open(inputfile.c_str());


    char quiz[maxstudents+1][11];
    int studentid[maxstudents];

for (int c = 0; c<maxstudents; c++)
{
infile>> studentid[c] >> quiz[c]; 
}

for (int r=0; r<maxstudents; r++)
cout<<quiz[r]<<"\t"; 
return o;
}

visually verify the data file is correct -- no blank lines and every line has the same format.

Please provide several lines from the file and how it is to be interpretted. I suspect you are setting up the arrays incorrectly.

For example, if the file looks like this:
ABC
BBA
CBB

then

char quiz[3][3];

for(i = 0; i < 3; i++)
  for(j = 0; j < 3; j++)
     infile >> quiz[i][j];

could be used to hold the entire contents of the file and maintain the relationships between lines, etc. Then if you assigned student number by index of number of the row of the array, you could output the student number and the scores of each student like this:

for(i = 0; ...)
  cout << "student" << i << ;
  for(j = 0; ...)
    cout << quiz[i][j] << ' ';
  cout << endl;

However, without knowing exactly how the file looks, and what you are supposed to do with it, these are just possibilities. There are many different possible scenarios regarding how the file is set up and several different ways to accomplish any given task to use the data in the file, but first you must know the specifics of the data, what you want to do with the data, and what tools you have available to accomplish the task.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.