我正在努力完成此代碼。File.cpp:148:錯誤:在'。'之前預期的主表達式令牌不同符號
#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++編譯器中運行。
File.cpp:170:warning:不能通過'...'傳遞非POD類型'struct std :: string'的對象;調用將在運行時中止。是我添加逗號時得到的。 –
這就是我提到的最後一點的錯誤。 fscanf()不知道std :: string。所以你必須使用臨時c字符串fscanf(stdin,「%s%s%s%s%s%s%s%s1f」 – 999k