#include <iostream>
#include <windows.h>
#include <fstream>
#include <cstring>
usingnamespace std;
int main()
{
int array[10][10];
for(int i = 0; i < 10; i++)
{
for(int p = 0; p < 10; p++)
{
array[i][p] = 7;
}
}
ifstream input("test.txt", ios::in);
int iarray[10][10];
for(int y = 0; y < 10; y++)
{
for(int x = 0; x < 10; x++)
{
input >> iarray[y][x];
cout << iarray[y][x] << " ";
}
cout << endl;
}
system("PAUSE");
return 0;
}
It looks like it should run correctly, but when I compile all I get is a series of random numbers. I know it's something to do with line 25, but I just don't know what. And just for reference, this is what test.txt looks like:
The extraction operator (>>) uses whitespace to delimit values, so as coder777 points out, you are reading in the number 7777777777 instead of the desired 7?
Thanks, the white space was what was wrong. I changed the function that created the file to include white spaces, and now it works just fine. Thanks everyone.