Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C+中的逻辑错误+;视觉工作室。数组是打印地址而不是内容 我在C++ Visual Studio中遇到了代码问题。我已经制作了一个数组MonthDays来存储其中一个月的日期。在DaysOfTheYear的构造函数中,我有一个字符串month,将月份设置为整数,将该整数放入checker变量中。使用这个checker变量,我试图打印数组的内容,但是数组打印的是我假设的变量地址。下面是代码。在第79行,我让它在void print函数中打印数组的内容,但它当然是打印出地址。我还没有在第79行输入代码,如果我输入60,它将等于3月1日。我只是在测试这个部分,以确保我在数组中打印出了正确的元素。在第13行,我用12个元素在DayOfYear类中声明MonthDays[12]。在第136行中,我定义了MonthDays数组,其中包含一个月的所有日期。我还知道,与第一个构造函数一样,它工作得很好,但是我应该在一个新的构造函数中添加一个字符串变量和一个整数变量,在这种情况下,它可以确定日-月格式的日期_C++_Arrays - Fatal编程技术网

C+中的逻辑错误+;视觉工作室。数组是打印地址而不是内容 我在C++ Visual Studio中遇到了代码问题。我已经制作了一个数组MonthDays来存储其中一个月的日期。在DaysOfTheYear的构造函数中,我有一个字符串month,将月份设置为整数,将该整数放入checker变量中。使用这个checker变量,我试图打印数组的内容,但是数组打印的是我假设的变量地址。下面是代码。在第79行,我让它在void print函数中打印数组的内容,但它当然是打印出地址。我还没有在第79行输入代码,如果我输入60,它将等于3月1日。我只是在测试这个部分,以确保我在数组中打印出了正确的元素。在第13行,我用12个元素在DayOfYear类中声明MonthDays[12]。在第136行中,我定义了MonthDays数组,其中包含一个月的所有日期。我还知道,与第一个构造函数一样,它工作得很好,但是我应该在一个新的构造函数中添加一个字符串变量和一个整数变量,在这种情况下,它可以确定日-月格式的日期

C+中的逻辑错误+;视觉工作室。数组是打印地址而不是内容 我在C++ Visual Studio中遇到了代码问题。我已经制作了一个数组MonthDays来存储其中一个月的日期。在DaysOfTheYear的构造函数中,我有一个字符串month,将月份设置为整数,将该整数放入checker变量中。使用这个checker变量,我试图打印数组的内容,但是数组打印的是我假设的变量地址。下面是代码。在第79行,我让它在void print函数中打印数组的内容,但它当然是打印出地址。我还没有在第79行输入代码,如果我输入60,它将等于3月1日。我只是在测试这个部分,以确保我在数组中打印出了正确的元素。在第13行,我用12个元素在DayOfYear类中声明MonthDays[12]。在第136行中,我定义了MonthDays数组,其中包含一个月的所有日期。我还知道,与第一个构造函数一样,它工作得很好,但是我应该在一个新的构造函数中添加一个字符串变量和一个整数变量,在这种情况下,它可以确定日-月格式的日期,c++,arrays,C++,Arrays,我的输出如下: -8589934060(这应该是数组的内容)第365天是12月31日。 如果有人能帮上忙,我将不胜感激。谢谢大家阅读这篇文章 // This program takes a user inputted integer and converts it to a month and day #include <iostream> #include <string> #include <iomanip> #include <Wind

我的输出如下:

-8589934060(这应该是数组的内容)第365天是12月31日。 如果有人能帮上忙,我将不胜感激。谢谢大家阅读这篇文章

 // This program takes a user inputted integer and converts it to a month and day

 #include <iostream>
 #include <string>
 #include <iomanip>
 #include <Windows.h>

 using namespace std;

 class DayOfYear
 {
     public:
         int MonthDays[12];
         int day;
         static string monthName;
         int checker;

         DayOfYear(int dayD)
         {
             day = dayD;
         }
         DayOfYear(int days, string month)
         {
             day = days;
             if (month == "January")
             {
                checker = 1;
             }
             else if (month == "February")
             {
                 checker = 2;
             }
             else if (month == "March")
             {
                checker = 3;
             }  
             else if (month == "April")
             {
                 checker = 4;
             }
             else if (month == "May")
             {
                 checker = 5;
             }
             else if (month == "June")
             {
                 checker = 6;
             }
             else if (month == "July") 
             {
                 checker = 7;
             }
             else if (month == "August")
             {
                 checker = 8;
             }
             else if (month== "September")
             {
                 checker = 9;
             }
             else if (month == "October")
             {
                 checker = 10;
             }
             else if (month == "November")
             {
                checker = 11;
             }
             else if (month == "December")
             {
                checker = 12;
             }

         }


     void print()
     {
         cout << MonthDays[checker - 1];

         if (day >= 1 && day <= 31)
         {
             cout << "Day " << day << " would be January " << day;
         }
         else if (day >= 32 && day <= 59)
         {
             cout << "Day " << day << " would be February " << day - 31;
         }
         else if (day >= 60 && day <= 90)
         {
             cout << "Day " << day << " would be March " << day - 59;
         }
         else if (day >= 91 && day <= 120)
         {
             cout << "Day " << day << " would be April " << day - 90;
         }
         else if (day >= 121 && day <= 151)
         {
             cout << "Day " << day << " would be May " << day - 120;
         }
         else if (day >= 152 && day <= 181)
         {
             cout << "Day " << day << " would be June " << day - 151;
         }
         else if (day >= 182 && day <= 212)
         {
             cout << "Day " << day << " would be July " << day - 181;
         }
         else if (day >= 213 && day <= 243)
         {
             cout << "Day " << day << " would be August " << day - 212;
         }
         else if (day >= 244 && day <= 273)
         {
             cout << "Day " << day << " would be September " << day - 243;
         }
         else if (day >= 274 && day <= 304)
         {
             cout << "Day " << day << " would be October " << day - 273;
         }
         else if (day >= 305 && day <= 334)
         {
             cout << "Day " << day << " would be November " << day - 304;
         }
         else if (day >= 335 && day <= 365)
         {
             cout << "Day " << day << " would be December " << day - 334;
         }
     }

 };


 int main()
 {
     int MonthDays[] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };

     DayOfYear tester(365,"February");
     tester.print();

     Sleep(5000);

 }
//此程序接受用户输入的整数,并将其转换为一个月和一天
#包括
#包括
#包括
#包括
使用名称空间std;
上课日
{
公众:
国际月日[12];
国际日;
静态字符串名称;
整数检查器;
年月日(整数日)
{
天=天;
}
DayOfYear(整数天,字符串月)
{
天=天;
如果(月份=“一月”)
{
检查器=1;
}
否则,如果(月份=“二月”)
{
检查器=2;
}
否则,如果(月份=“三月”)
{
检查器=3;
}  
否则,如果(月份=“四月”)
{
检查器=4;
}
否则,如果(月份=“五月”)
{
检查器=5;
}
否则,如果(月份=“六月”)
{
检查器=6;
}
否则,如果(月份=“7月”)
{
检查器=7;
}
否则,如果(月份=“八月”)
{
检查器=8;
}
否则,如果(月份=“9月”)
{
检查器=9;
}
否则,如果(月份=“十月”)
{
检查器=10;
}
否则,如果(月份=“11月”)
{
检查器=11;
}
否则,如果(月份=“12月”)
{
检查器=12;
}
}
作废打印()
{
cout=1&&day变化:

 int MonthDays[12];
致:

这将设置类的数组

还要注意的是

cout << MonthDays[checker - 1];

accessign MonthDays是一个成员变量,它没有初始化,而不是您在main中声明的一个实际上从未使用过的变量。请将代码缩减为。您不需要显示(和解释)您的整个程序只需要询问一个输出语句。您有两个不同的数组,都名为
MonthsDays
@StoryTeller IMO这是一个MVCE,代码的描述有点过分了,我会告诉您,但是代码非常小,并且完整/可验证。它很长,因为冗长的if/else链。哦,是的如果使用第一个(一个参数)构造函数,则不要初始化 CuffkK/Cuth>。在C++中,未初始化的变量将具有不确定的值,使用它们导致未定义的行为。谢谢您的帮助米哈伊尔。我很感激。
cout << MonthDays[checker - 1];