gpt4 book ai didi

c++ - 文件.cpp :148: error: expected primary-expression before ‘.’ token DIFFERENT SYMBOL

转载 作者:行者123 更新时间:2023-11-28 00:47:29 25 4
gpt4 key购买 nike

我正在努力完成这段代码。

#include (sorry but it won't show up the #include such as stdio.h AND OTHERS) But this is not the problem.


using namespace std;


struct CustomerFile {
int arrivalTime;

string driverfName,
driverlName,
typeOfDriver,
driverLicNumber,
vehicleMake,
vehicleModel,
Lot_taken,
vehicleRegNumber,
attendantName,
ParkingArea,
Comments,
checkOutDateTime,
checkInDateTime;
};

int arrivalTime;

string driverfName,

driverlName,
typeOfDriver,
driverLicNumber,
vehicleMake,
vehicleModel,
Lot_taken,
vehicleRegNumber,
attendantName,
ParkingArea,
Comments,
checkOutDateTime,
checkInDateTime;

int main(int argc, char * * argv) {

FILE * cfPtr;

if ((cfPtr = fopen("CustomerFile.dat", "rb+")) == NULL) {
printf("file could not be opened");
} else {
printf("\nFile is Written to");
printf("\nFile is open");

printf("\n\n\nEnter Vehicle Registration Number: ");
scanf("%s", & CustomerFile.vehicleRegNumber);

while (CustomerFile.vehicleRegNumber != 0) /*#IF THE USER does not enter 0 the loops should begin, but there is a problem here*/
{

printf("\nFirst Name: ");
fscanf("%s", CustomerFile.driverfName); /*here is the problem, I think is had something to do with the struct name*/
printf("\nLast Name: ");
printf("\nType of Driver: ");
printf("\nDriver's License Number: ");
printf("\nVehicle Make: ");
printf("\nVehicle Model: ");
printf("\nComments ");
printf("\nParking SpaceTaken ");

printf("\n\nenter firstname, lastname");
fscanf(stdin, "%s%s%s%s%s%s%s%s1f", CustomerFile.driverfName I think this has something to do with the statement * /
CustomerFile.driverlName / * okay here * /
CustomerFile.typeOfDriver / * okay here * /
CustomerFile.driverLicNumber / * okay here * /
CustomerFile.vehicleMake / * okay here * /
CustomerFile.vehicleModel / * okay here * /
CustomerFile.Comments / * okay here * /
&CustomerFile.Lot_taken); / * okay here * /


fwrite( sizeof(struct CustomerFile ), 1, cfPtr);




}
fclose( cfPtr);
}


return 0;

}

好吧,问题是它一直报错;*

File.cpp:144: error: expected primary-expression before ‘.’ token

File.cpp:148: error: expected primary-expression before ‘.’ token

File.cpp:162: error: expected primary-expression before ‘.’ token

File.cpp:172: error: invalid conversion from ‘unsigned int’ to ‘const void*’

File.cpp:172: error: invalid conversion from ‘FILE*’ to ‘size_t’ /usr/include/stdio.h:708: error: too few arguments to function ‘size_t fwrite(const void*, size_t, size_t, FILE*)’ File.cpp:172: error: at this point in file

我相信或读到它与 C++ 编译器不适用于 c99 这一事实有关。如果是这样,那么您如何在 C++ 中使用结构?我知道你使用一个结构,例如 CustomerFile.driverlName,但是,编译器一直拒绝它。我也遇到了 while 循环的问题。我熟悉 c 和 c++,我们学过 c 和 c++,代码将用 c++ 编写,但教科书提供的 c 代码无法在 c++ 编译器中运行。

最佳答案

CustomerFile 是一个类,因此当您尝试访问它的数据成员时它不会工作,就好像它是一个实例。要创建实例,请执行以下操作:

CustomerFile file;

并将 Customer. 的所有实例替换为 file.,它应该可以解决错误。

关于c++ - 文件.cpp :148: error: expected primary-expression before ‘.’ token DIFFERENT SYMBOL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15736581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com