当city数组中的字符串数与数据相同时会显示,但是当字符串数小于数据时则不会进入循环体,但是循环的判断条件为true,但是不执行里面的语句,以下代码是我测试的
#include <stdio.h>
#include <iostream>
const int Cities = 5;
const int Years = 4;
int main()
{
using namespace std;
const char* cities[Cities] =
{
"Gribble City",
"Gribbletown",
//"New Gribble",
//"San Gribble",
"Gribble Vista"
};
int maxtemps[Years][Cities] = {
{96, 100, 87, 101, 105},
{96, 98, 91, 107, 104},
{97, 101, 93, 108, 107},
{98, 103, 95, 109, 108}
};
cout << "Maximum tempertures for 2008 - 2011\n\n";
for (int city = 0; city < Cities; ++city)
{
if (city == 4)
cout << "You have found me." << endl;
cout << cities[city] << ":\t";
for (int year = 0; year < Years; year++)
cout << maxtemps[year][city] << "\t";
cout << endl;
}
system("pause");
return 0;
}
实际只输出前三个数组的数据