File.cpp:148: error: expected primary-expression before ‘.’ token DIFFERENT SYMBOL
我正在努力完成这段代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #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(" File is Written to"); printf(" File is open"); printf(" Enter 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(" First Name:"); fscanf("%s", CustomerFile.driverfName); /*here is the problem, I think is had something to do with the struct name*/ printf(" Last Name: "); printf(" Type of Driver: "); printf(" Driver's License Number: "); printf(" Vehicle Make: "); printf(" Vehicle Model: "); printf(" Comments "); printf(" Parking SpaceTaken"); printf(" enter 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++中如何使用Struts?我知道你使用了一个结构,比如customerfile.driverlname,但是编译器一直拒绝使用它。另外,while循环也有问题。我熟悉C和C++,我们同时教了C和C++,代码是用C++编写的,但是教科书给出了C代码,这些代码不能在C++编译器中运行。
1 | CustomerFile file; |
用
您定义了一个数据类型
1 2 | CustomerFile customer; customer.vehicleModel ="ABC"; |
1 | while (customer.vehicleRegNumber !="0" ) |
在变量名之间加上
1 | fscanf( stdin,"%s%s%s%s%s%s%s%s1f", customer.driverfName, customer.driverlName , |
1 2 3 4 5 | char temp[100]; printf(" First Name:"); fscanf(stdin,"%99s", temp ); customer.driverfName = temp; |