Reading data from two text files

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include <string>
using namespace 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.
what if i did a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
        string word;

        fstream textfile;
        textfile.open("./student.txt");
        textfile >> word;
        cout << word << endl;

        textfile.close();
        return 0;
}

then
1
2
if (argc == word)
     getline(dataFile, input) // input is the string to hold the imported information 


else keep looking

is this the right strategy?
Topic archived. No new replies allowed.