eyys666 发表于 2020-4-18 14:26:40

代码报错

这段代码报错是什么原因Compiling...
1.cpp
D:\VC++\Microsoft Visual Studio\MyProjects\3\1.cpp(34) : error C2039: 'birthbay' : is not a member of '__unnamed'
      D:\VC++\Microsoft Visual Studio\MyProjects\3\1.cpp(13) : see declaration of '__unnamed'
D:\VC++\Microsoft Visual Studio\MyProjects\3\1.cpp(34) : error C2228: left of '.month' must have class/struct/union type
D:\VC++\Microsoft Visual Studio\MyProjects\3\1.cpp(35) : error C2039: 'birthbay' : is not a member of '__unnamed'
      D:\VC++\Microsoft Visual Studio\MyProjects\3\1.cpp(13) : see declaration of '__unnamed'
D:\VC++\Microsoft Visual Studio\MyProjects\3\1.cpp(35) : error C2228: left of '.month' must have class/struct/union type
执行 cl.exe 时出错.
#include <stdio.h>

void main()
{
      struct date
      {
            int month;
            int day;
            int year;
      };

      struct
      {
            int num;
            char name;
            char sex;
            struct date birthday;
            float score;
      } boy1, boy2;
      
      printf("Please input birthday(YY;)");
      scanf("%d", &boy1.birthday.year);

      printf("Please input birthday(MM:)");
      scanf("%d", &boy1.birthday.month);

      printf("Please input birthday(DD;)");
      scanf("%d", &boy1.birthday.day);

      printf("\n");

      boy2 = boy1;

      printf("boy1's birthday is %d-%d-%d\n", boy1.birthday.year, boy1.birthbay.month, boy1.birthday.day);
      printf("boy1's birthday is %d-%d-%d\n", boy2.birthday.year, boy2.birthbay.month, boy2.birthday.day);
}

我叫MD 发表于 2020-4-18 15:58:55

boy1.birthbay.month   改为boy1.birthday.month

birthbay这个单词拼错了
页: [1]
查看完整版本: 代码报错