我在处理结构数组时遇到问题。这是我生成 2 条红色错误行的代码。
struct frequents
{
int count;
char letter;
};
frequents testArray[2];
testArray[1].letter = 'v';
错误出现在具有声明错误的 testArray 下和“.”下其中提到它需要一个“;”。
最佳答案
这是一个 statement :
testArray[1].letter = 'v';
语句将在函数(函数体)内执行,而不是像现在这样在某个任意的全局命名空间中执行。在主程序中移动您的语句 entry point function , 一个 lambda ,一个独立的function或 class成员函数体。
或者,使用 aggregate initialization初始化你的数组:
frequents testArray[2] = {{ 1, 'a' }, { 2, 'b' }};
或者没有额外的大括号:
frequents testArray[2] = { 1, 'a', 2, 'b' };
关于c++结构数组 - "This declaration has no storage class or type specifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51171751/