关于非类类型错误的问题? 我是C++新手,我一直在尝试处理输入的级联。我有一个用户输入的名字和姓氏以及假社会保险的最后四位数字。然后我想把它们加在一起,取名字的第一个字母,姓氏的第一个字母和四个数字。每次我运行程序时,非类类型的错误就会弹出。 错误: 函数'int main()':89:26:错误:请求'firstname[i]'中的'at'成员,该成员为非类类型'string2{aka char[3]}'90:26:错误:请求'lastname[i]'中的'at'成员,该成员为非c`在此处输入代码'lass type'string2{aka char[3]}' typedef char string2[大小]; string2 firstname[大小]; string2 lastname[大小]; 字符串2初始[大小]; string2 lastfour[尺寸]; //ID的浓缩 字符串id[大小]; 对于(int i=0;i
您使用的变量都声明为关于非类类型错误的问题? 我是C++新手,我一直在尝试处理输入的级联。我有一个用户输入的名字和姓氏以及假社会保险的最后四位数字。然后我想把它们加在一起,取名字的第一个字母,姓氏的第一个字母和四个数字。每次我运行程序时,非类类型的错误就会弹出。 错误: 函数'int main()':89:26:错误:请求'firstname[i]'中的'at'成员,该成员为非类类型'string2{aka char[3]}'90:26:错误:请求'lastname[i]'中的'at'成员,该成员为非c`在此处输入代码'lass type'string2{aka char[3]}' typedef char string2[大小]; string2 firstname[大小]; string2 lastname[大小]; 字符串2初始[大小]; string2 lastfour[尺寸]; //ID的浓缩 字符串id[大小]; 对于(int i=0;i,c++,types,compiler-errors,concatenation,C++,Types,Compiler Errors,Concatenation,您使用的变量都声明为char[][]。要使用at(),您需要选择std::string,因为它是该类的成员函数 或者,您可以使用操作符[]访问jth条目的ith字符,例如,firstname[j].[i]尝试firstname[i][0]。 In function 'int main()': 89:26: error: request for member 'at' in 'firstname[i]', which is of non-class type 'string2 {aka char
char[][]
。要使用at()
,您需要选择std::string
,因为它是该类的成员函数
或者,您可以使用
操作符[]
访问j
th条目的i
th字符,例如,firstname[j].[i]
尝试firstname[i][0]
。
In function 'int main()': 89:26: error: request for member 'at' in 'firstname[i]', which is of non-class type 'string2 {aka char [3]}' 90:26: error: request for member 'at' in 'lastname[i]', which is of non-c`enter code here`lass type 'string2 {aka char [3]}'
typedef char string2[size];
string2 firstname[size];
string2 lastname[size];
string2 middleinitial[size];
string2 lastfour[size];
//CONCATINATION FOR ID
string id[size];
for (int i = 0; i < size; i ++)
{
id [i] = firstname[i].at (0);//set id = to first letter of the first name
id [i] += lastname[i].at (1);//concatinate the first letter of the last name to the id
id [i] += lastfour[i]; //concatinate the last four
}