繁体   English   中英

File.cpp:148:错误:“。”之前的预期主表达式。 令牌不同符号

[英]File.cpp:148: error: expected primary-expression before ‘.’ token DIFFERENT SYMBOL

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

#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 *'的无效转换

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代码。

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

CustomerFile file;

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

您定义了数据类型CustomerFile 为了使用定义的结构CustomerFile您已经创建了一个对象并使用它。 例如:

CustomerFile  customer; 
customer.vehicleModel = "ABC"; 

vehicleRegNumber是字符串类型,不是整数,将其与0进行比较,就像这样

while (customer.vehicleRegNumber != "0" )

添加,变量名之间

  fscanf( stdin, "%s%s%s%s%s%s%s%s1f", customer.driverfName, customer.driverlName ,

fscanf()函数是C函数,它不了解std::string (或类)。 所以你使用了这样的临时字符串

      char temp[100];
      printf("\nFirst Name: ");
      fscanf(stdin, "%99s", temp );
      customer.driverfName = temp;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM