Hello!
To start off with I am trying to pass a argument through the command line and look through two .text files. For example I would input a student number (lets says 111222333) from the command line, it would then look through both .txt files and display information pertain to that student.
The trouble i'm having is how to solve this problem mentally. I know how to read lines of data from a text file, but i have no clue how to compare with a argument passed through the command line and then have it reference to the second .txt file.
If there is a website or somebody can try and break this down I would greatly appreciate it!!!
This is what i have (just reads the lines of code)
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main(int argc, char *argv[])
{
string input; //to hold file input
//open the file for input.
fstream dataFile("./student.txt",ios::in);
//if the file was successfully opened, continue
if (dataFile)
{
//read an item using ' ' as a delimiter
getline(dataFile, input, ' ');
//while the last read operatio was good, continue
while (dataFile)
{
//display the last item read.
cout << input << endl;
//read an item using ' ' as a delimiter
getline (dataFile, input, ' ');
}
//close the file.
dataFile.close();
}
else
{
cout <<"Error: Cannot open file.\n";
}
return 0;
}
again this just displays the contents of one text file. should i try and store the information on an array, but then i don't know how to compare and get data from the second text file.
there are two .txt files and they each start off with a 9 digit number and then has a couple sets of data behind it. i would like to input the students number and display all the information that is listed in both .txt files.