jeudi 29 juillet 2021

How to verify if 2 string variables are equal from 2 different files?

      file1.txt

How to apply for financial aid? (file1var)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      file2.txt

How to apply for financial aid? (file2var)

By going to the financial aid office (file2var2)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I am trying to verify if the string variable(file1var) for file 1(file1.txt) is equal to the 1st string variable(file2var) in file 2(file2.txt). And if they are equal, I am trying to ouput the first variable(file2var) and second variable(file2var2) of file 2(file2.txt) in the terminal.

#include <iostream>
#include <string>
#include <fstream>
#include<stdlib.h>
#include<string.h>
#include<ctime>
using namespace std;


int main(){
    
    string file1var, file2var, file2var2;
    int count;
    ifstream y("file1.txt");
    ifstream x("file2.txt");
        while(y>>file1var && x>>file2var>>file2var2)
        {
                if(file1var==file2var)
                {
                        count=1;
                }
        }
        y.close();
        x.close();
        if(count==1){
            cout<<file2var<<file2var2<<endl;
        }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire