在c++中读取两个文件并进行比较

Reading two Files and comparing in C++

本文关键字:文件 两个 比较 c++ 读取      更新时间:2023-10-16

我一直在尝试将用户输入与文件进行比较,我能够打开它。我来展示一下

cout<< "Please Enter your Student ID:  ";
 cin >> stdID;
 cout<< "Please Enter your Course ID:  ";
 cin >> courseID;
 if the courseID is similar to the prerequisite file, eligible, if not, not eligible..
    this is the file     
    course Prereq
    cs111 NA
    cs112 cs111
    cs240 cs112
    cs241 cs240
    cs214 cs112
    cs215 cs112
    cs218 cs111
    cs310 cs215
    cs311 cs112
    cs317 cs215
    cs318 cs218
    cs324 cs240
    cs341 cs241

对于像这样简单的东西,我会在一个简单的while循环中读取输入,使用输入操作符>>读取两个字符串(并依赖于operator>>函数返回流的事实,并且流可以在布尔条件下使用)。

然后在循环中将用户输入的字符串与第一个字符串进行比较,如果匹配,则输出第二个字符串(如果不是,例如"NA")。