error: invalid types ‘unsigned int[unsigned int]’ for array subscript
Why am I getting invalid type on
Project1.cpp:139:32: error: invalid types ‘unsigned int[unsigned int]’ for array subscript
os << Mon[month(date)-1];
Code:
void displayDate(const Date& date, ostream& os, DATE_STYLE ds)
{
// if ds == MM_DD_YYYY)
if (!wellFormed(date))
{
cout << "Date Error\n";
exit(1);
}
else
if (ds == MM_DD_YYYY)
{
if (numDigits(date) == 7)
os << '0';
os << month(date) << '/';
if (nthDigit(date, 5) == 0)
os << '0';
os << day(date) << '/';
unsigned y = year(date);
unsigned len = 4 - numDigits(y);
for (unsigned i = 0; i < len; ++i)
os << '0';
os << year(date) << endl;
}
else
string Mon[12] = {"Jan ", "Feb ", "Mar ", "Apr ", "May ", "June ", "Jul ", "Aug ",
"Sept ", "Oct ", "Nov ", "Dec " };
unsigned Mon;
os << Mon[month(date)-1];
if (nthDigit(date, 5) == 0)
os << '0';
os << day(date) << ",";
unsigned y = year(date);
unsigned len = 4 - numDigits(y);
for (unsigned i = 0; i < len; ++i)
{
os << '0';
os << year(date) << endl;
}
}
Re: error: invalid types ‘unsigned int[unsigned int]’ for array subscript
Please, always add CODE tags around code snippets!
Read the Announcement: Before you post....
Re: error: invalid types ‘unsigned int[unsigned int]’ for array subscript
Will do! thanks for the help
Re: error: invalid types ‘unsigned int[unsigned int]’ for array subscript
Well, now look at the formatted code snippet...
this part:
Code:
else
if (ds == MM_DD_YYYY)
{
if (numDigits(date) == 7)
os << '0';
os << month(date) << '/';
if (nthDigit(date, 5) == 0)
os << '0';
os << day(date) << '/';
unsigned y = year(date);
unsigned len = 4 - numDigits(y);
for (unsigned i = 0; i < len; ++i)
os << '0';
os << year(date) << endl;
}
else
string Mon[12] = {"Jan ", "Feb ", "Mar ", "Apr ", "May ", "June ", "Jul ", "Aug ",
"Sept ", "Oct ", "Nov ", "Dec " };
unsigned Mon;
is the same as if you would write it as
Code:
else if (ds == MM_DD_YYYY)
{
if (numDigits(date) == 7)
{
os << '0';
}
os << month(date) << '/';
if (nthDigit(date, 5) == 0)
{
os << '0';
}
os << day(date) << '/';
unsigned y = year(date);
unsigned len = 4 - numDigits(y);
for (unsigned i = 0; i < len; ++i)
{
os << '0';
}
os << year(date) << endl;
}
else
{
string Mon[12] = {"Jan ", "Feb ", "Mar ", "Apr ", "May ", "June ", "Jul ", "Aug ",
"Sept ", "Oct ", "Nov ", "Dec " };
}
unsigned Mon;
...
Is it the same as you have expected? :confused:
Re: error: invalid types ‘unsigned int[unsigned int]’ for array subscript
Quote:
Originally Posted by
thishas
Why am I getting invalid type on
This seems bogus to me,
Code:
unsigned Mon;
os << Mon[month(date)-1];
You are declaring Mon to be an ordinary unsigned int but then you use it as if it were an array.
The other Mon,
Code:
string Mon[12] = .......;
is out of scope as VictorN suggests.