对成员.. in ..的错误请求,该请求是非类型-C++
我有一个错误:“错误:'tablou [j]''的nume'请求,该'tablou [j]'是非类型'[100]''的请求,我真的不知道如何解决。尝试在YouTube和Google上搜索,但我什么也没发现。有人对如何解决这个问题有任何想法吗?
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct{
int counter;
char nume[20] = " ";
}tablou[10][100];
int main()
{
int n, counter = 0;
char second[10][100];
bool verify = true;
cout<<"Cate nume?";
cin>>n;
for(int i = 0; i <= n; i++)
{
cin.getline(second[i],20);
}
for(int i = 0; i <= n; i++)
{
verify = true;
for(int j = 0; j < i; j++)
{
if(strcmp(second[i], tablou[j].nume) == 0)
{
verify = false;
}
}
if(verify == true)
{
strcpy(tablou[i].nume, second[i]);
for(int k = 0; k < n; k++)
{
if(strcmp(tablou[i].nume, second[k]))
{
tablou[i].counter++;
}
}
}
}
for(int i = 0; i <= n; i++)
{
cout<<tablou[i].nume<<" "<<tablou[i].counter<<endl;
}
return 0;
}
I have got this error: "error: request for member 'nume' in 'tablou[j]', which is of non-class type ' [100]'", and I don't really know how to solve it.I tried searching on youtube and google but I found nothing .Does anyone have any ideas for how to solve this?
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct{
int counter;
char nume[20] = " ";
}tablou[10][100];
int main()
{
int n, counter = 0;
char second[10][100];
bool verify = true;
cout<<"Cate nume?";
cin>>n;
for(int i = 0; i <= n; i++)
{
cin.getline(second[i],20);
}
for(int i = 0; i <= n; i++)
{
verify = true;
for(int j = 0; j < i; j++)
{
if(strcmp(second[i], tablou[j].nume) == 0)
{
verify = false;
}
}
if(verify == true)
{
strcpy(tablou[i].nume, second[i]);
for(int k = 0; k < n; k++)
{
if(strcmp(tablou[i].nume, second[k]))
{
tablou[i].counter++;
}
}
}
}
for(int i = 0; i <= n; i++)
{
cout<<tablou[i].nume<<" "<<tablou[i].counter<<endl;
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tablou是一个2D数组,
其元素是
tablou [x] [y]
您尝试访问只有一个索引的元素
,我不知道您的代码要做什么错误
tablou is a 2d array
its elements are
tablou[x][y]
you try to access an element with only one index
I do not know what your code is trying to do , but thats why you get the error
数组
tableou
是一个二维的数组,例如表达式
tablou [j]
具有数组类型the_unnamed_structure [100]。因此,这样的表达
不正确,并且编译器会发出错误。
以下声明。
也许实际上,您的意思是在这些循环中,也
可以在数组的某些元素
tablou
中进行 因为您使用索引i
来分配数组tablou
的元素。那就是数组tableou
的实际元素数量可以小于n
。在这种情况下,对于循环,这将调用未定义的行为,因为数据成员
counter
对于数组的某些输出元素将不进行原始化。您需要支持一个单独的变量作为数组
tablou
中的索引。The array
tablou
is a two-dimensopnal arraySo for example the expression
tablou[j]
has the array type the_unnamed_structure[100].So such an expression like this
is incorrect and the compiler issues an error.
Maybe actually you mean the following declaration of the array
Also in these loops
some elements of the array
tablou
can be skipped ifverify
is set tofalse
because you are using the indexi
to assign elements of the arraytablou
. That is the number of actual elements of the arraytablou
can be less thann
. In this case this for loopwill invoke undefined behavior because the data member
counter
will be uninitialized for some outputted elements of the array.You need to support a separate variable as an index in the array
tablou
.