我正在努力完成这段代码。
#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:错误:“。”之前的预期主表达式 令牌
File.cpp:148:错误:“。”之前的预期主表达式 令牌
File.cpp:162:错误:“。”之前的预期主表达式 令牌
File.cpp:172:错误:从 'unsigned int' 到 'const void*' 的无效转换</p>
File.cpp:172: 错误: 从 'FILE*' 到 'size_t' /usr/include/stdio.h:708: 错误: 函数'size_t fwrite(const void*, size_t, size_t, FILE)的参数太少*)' File.cpp:172: 错误:此时在文件中
我相信或读到它与 C++ 编译器不适用于 c99 的事实有关。如果是这样,那么您如何在 C++ 中使用结构?我知道您仅通过 CustomerFile.driverlName 使用结构,但是,编译器一直拒绝它。我也遇到了while循环的问题。我熟悉 c 和 c++,我们同时学习了 c 和 c++,代码要用 c++ 编写,但教科书提供的 c 代码不能在 c++ 编译器中运行。