I'm trying to get this simple File I/O code to work but it just outputs junk. Can anybody tell me what the problem is?
Code:
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream map(argv[1]);
//cout<<argv[1];
int height, width, length;
int *numbers;
char name[10];
map>>name>>height>>width;
length = width * height;
numbers = new int[length];
cout<<name<<"\n";
cout<<height<<" x "<<width<<" = "<<length<<"\n";
int n;
for (n = 0; n < length; n++) {
map>>numbers[n];
numbers[n] -= 1;
cout<<numbers[n]<<" ";
}
map.close();
ofstream mapo("output.txt");
cout<<"------------------------\n";
for (n = 0; n < length; n++) {
//cout<<numbers[n]<<" ";
mapo<<numbers[n]<<" ";
}
mapo.close();
system("PAUSE");
return 0;
}
I've attached the input and output files.
EDIT: Nevermind, I figured it out. Don't know how.... but I did.