chris200x9
March 1st, 2010, 03:16 AM
My ifstream is broken plain and simple. I've followed many tutorials, I've even posted here and everything looks right. I'm begging someone find what's wrong with this:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
ifstream inData;
inData.open("out.txt");
int matrix2[9][9];
int counter = 0;
int i =0;
while(!inData.eof())
{
while (i < 9)
{
while (counter < 9)
{
inData >> matrix2[i][counter];
counter++;
}
counter = 0;
i++;
}
}
inData.close();
cout << matrix2[0][0];
return 0;
}
here is the contents of out:
0 3 0 9 0 2 0 4 0
6 0 0 0 0 0 0 0 5
0 0 0 0 1 0 0 0 0
8 0 0 2 0 3 0 0 7
0 0 4 0 5 0 6 0 0
9 0 0 7 0 8 0 0 2
0 0 0 0 9 0 0 0 0
7 0 0 0 0 0 0 0 1
0 5 0 6 0 4 0 9 0
When I run the program nothing happens, I have to hit control c.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
ifstream inData;
inData.open("out.txt");
int matrix2[9][9];
int counter = 0;
int i =0;
while(!inData.eof())
{
while (i < 9)
{
while (counter < 9)
{
inData >> matrix2[i][counter];
counter++;
}
counter = 0;
i++;
}
}
inData.close();
cout << matrix2[0][0];
return 0;
}
here is the contents of out:
0 3 0 9 0 2 0 4 0
6 0 0 0 0 0 0 0 5
0 0 0 0 1 0 0 0 0
8 0 0 2 0 3 0 0 7
0 0 4 0 5 0 6 0 0
9 0 0 7 0 8 0 0 2
0 0 0 0 9 0 0 0 0
7 0 0 0 0 0 0 0 1
0 5 0 6 0 4 0 9 0
When I run the program nothing happens, I have to hit control c.