我從來沒有經歷過這樣的事情。我正在使用一個cout語句來幫助我調試一個小程序,一旦我對代碼感到滿意,我就註釋掉了cout。現在,代碼不再有效。以下是cout註釋的代碼。評論cout語句導致不同(和不正確)的輸出
該程序的目的是測試兩個硬編碼布爾二維數組的每行有奇數個真正的語句。因此,第一個數組應該返回true,第二個數組應該返回false。隨着cout聲明註釋掉,而是返回false。
#include <iostream>
using namespace std;
template <size_t size_y>
bool findEvenDegrees(bool mapArray[][size_y])
{
bool returnValue;
for (int x=0; x<size_y; x++)
{
int result = 0;
for (int y=0; y<size_y; y++)
{
result = result + mapArray[x][y];
//the line below causes the problem
cout << mapArray[x][y] << "\t" << result << "\t" << x << endl;
}
if (result%2 == 1)
{
returnValue = false;
break;
}
}
if (returnValue== false)
{
return returnValue;
}
else
{
return true;
}
}
int main()
{
bool array1[][6] =
{
{false,true,true,false,false,false},
{true,false,false,true,false,false},
{true,false,false,true,false,false},
{false,true,true,false,true,true},
{false,false,false,true,false,true},
{false,false,false,true,true,false}
};
bool array2[][8] =
{
{false,true,true,false,false,false,false,false},
{true,false,false,true,false,false,false,false},
{true,false,false,true,false,false,false,false},
{false,true,true,false,true,false,false,false},
{false,false,false,true,false,true,true,false},
{false,false,false,false,false,true,false,true},
{false,false,false,false,true,false,false,true},
{false,false,false,false,false,true,true,false}
};
bool answer1 = findEvenDegrees(array1);
bool answer2 = findEvenDegrees(array2);
if (answer1 == true)
{
cout << "Array 1 has a even degree for every switch." << endl;
}
else
{
cout << "Array 1 has a odd degree for at least one switch." << endl;
}
if (answer2 == true)
{
cout << "Array 2 has a even degree for every switch.";
}
else
{
cout << "Array 2 has a odd degree for at least one switch.";
}
return 0;
}
[評論出'cout'一部分。](http://coliru.stacked-crooked.com/view?id=94e5c41fe17a9a5f86815122c813b6a8-f674c1a6d04c632b71a62362c0ccfc51) –
任'size_y!= X || size_y!= y'。它們的大小與您在主要布爾數組中看到的大小不同。 – mr5