Hello all,
I have a file that I need to read into my program at the command line. This program should take this input file (e.g. input1) and store it in two different array. This is how my code looks like but it doesn't work. Someone please help.
This is what I would type in order to execute my program:
This is my input1 file:
Code:
1 2 3 4 5
1 2 4 4 5
This is my program:
Code:
#include <iostream>
#include <string>
#include <fstream>
// Global values and arrays
int preorder[26];
int inorder[26];
int main(int argc, char **argv){
if (argc != 1){
// report some error message
cerr << "Error";
exit(-1);
}
char *fileName = argv[2];
cout << argv[2];
// declared an ifstream object
ifstream in(fileName);
// if in cannot be opened, display error message
if (!in){
cerr << "File cannot be opened!\n";
exit(-1);
}
// read information into array preorder[]
int count = 0;
while ((!(in >> "\n")) || count <= 26){
cin >> preorder[count];
cout << preorder[count];
count++;
}
// read information into array inorder[]
count = 0;
while ((!(in >> "\n")) || count <= 26){
cin >> inorder[count];
cout << inorder[count];
count++;
}
return 0;
}
Someone please help. Thank you.