C++ C++;错误C2065未声明的标识符

C++ C++;错误C2065未声明的标识符,c++,visual-c++,C++,Visual C++,我有点困惑。我希望能够使用车辆类型显示carMake。如果我使用If语句使用年份,我会得到我想要的carMake。我无法让if(vehicleType==汽车)为我工作。请帮忙。先谢谢你 #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string vin, carMake, carModel, vehicleTy

我有点困惑。我希望能够使用车辆类型显示carMake。如果我使用If语句使用年份,我会得到我想要的carMake。我无法让if(vehicleType==汽车)为我工作。请帮忙。先谢谢你

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main ()
{
    string vin, carMake, carModel, vehicleType;
    int year, weight;
    ofstream fout;
    ifstream fin;
    fin.open ("VehicleInput.txt");
    fout.open("VehicleOutput.txt");   
    fout << "Vehicle Registration Information" << endl;

    while(!fin.eof())
    {

        fin >> vin;
        fin >> carMake;
        fin >> carModel;
        fin >> year;
        fin >> vehicleType;
        fin >> weight; 

        if (vehicleType == CAR)     //If I use if (year == 2007) it will spit out the carMake.
        { 
            cout << carMake << endl;
        }

    }
    fin.close();    
    fout.close();
    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串vin、carMake、carModel、vehicleType;
整年,体重;
流式流量计;
流鳍;
fin.open(“VehicleInput.txt”);
fout.open(“VehicleOutput.txt”);
福特文;
fin>>卡马克;
fin>>carModel;
fin>>年;
fin>>车辆类型;
鳍>>重量;
if(vehicleType==CAR)//如果我使用if(year==2007),它会吐出卡马克。
{ 

cout这可能就是你想要的:

if (vehicleType == "CAR")
{ 
    cout << carMake << endl;
}
if(车辆类型==“CAR”)
{ 

CUT< P>车辆类型是字符串类型的变量,所以它可以与一些字符串(如CouthLype=“Car”)进行比较,或者你可以考虑其他可用的字符串比较函数。< /P>如何使用“Car”代替Car?也改变你的while循环条件<代码>而(.FIN,EOF())< /C>不是这样做的,而是写“代码>”。(fin>>vin){…}
.eof()在读取文件末尾时触发,而不是在读取文件中的最后一个字符串时触发。