我正在尝试输出这个数组,我不知道我是否是个白痴,解决方案正在盯着我,或者这里有更多技术性的事情。
代码:
for ( string i=0;i<row; i++)
{
for ( string j=0; j<col; j++)
{
out << Array[i][j];
}
}
请注意,Array
是char
数据类型。 row
和col
定义为字符串。
我得到的错误来自Visual Studios(3个错误):
cpp(97): error C2676: binary '++': 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
cpp(99): error C2676: binary '++': 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
cpp(101): error C2677: binary '[': no global operator found which takes type 'std::string' (or there is no acceptable conversion)
请注意,我尝试使用整数而不是字符串作为计数器,但我收到更多错误......
我同意这些评论。您不应该仅仅为了删除错误或警告而与编译器作斗争,而应该尝试理解它们的含义并正确修复它们。在您的情况下,它会告诉您j++
和i++
是非法的,因为std::string
类型没有为其定义operator++
。
我建议你的Array
数据类型将行和列定义为int
,然后你可以写:
for ( int i=0;i<row; i++)
{
for ( int j=0; j<col; j++)
{
std::cout << Array[i][j];
}
}
假设 operator<<
对于 Array
类型是重载的,否则行:
std::cout << Array[i][j];
也将是非法的。