Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误C2228:位于';的左侧;。单词';必须具有类/结构/联合_C++_Visual Studio 2013 - Fatal编程技术网

C++ 错误C2228:位于';的左侧;。单词';必须具有类/结构/联合

C++ 错误C2228:位于';的左侧;。单词';必须具有类/结构/联合,c++,visual-studio-2013,C++,Visual Studio 2013,当我尝试使用VS2013编译此文件时,出现以下错误。我已经链接了这个文件,因为它看起来太大了,无法在这里复制和粘贴 Payload.cc(77) : error C2275: 'spectralFrameWord' : illegal use of this type as an expression Payload.cc(22) : see declaration of 'spectralFrameWord' Payload.cc(77) : error C2228: left of '.wo

当我尝试使用VS2013编译此文件时,出现以下错误。我已经链接了这个文件,因为它看起来太大了,无法在这里复制和粘贴

Payload.cc(77) : error C2275: 'spectralFrameWord' : illegal use of this type as an expression Payload.cc(22) : see declaration of 'spectralFrameWord' Payload.cc(77) : error C2228: left of '.words' must have class/struct/union cc(77):错误C2275:“spectralFrameWord”:非法使用此类型作为表达式 有效载荷.cc(22):参见“spectralFrameWord”声明 Payload.cc(77):错误C2228:“.words”的左边必须有class/struct/union 代码

#include <cstdio>
#include <cstdint>
using namespace std;

long getFileSize(FILE *file) {
    long currentPosition, endPosition;
    currentPosition = ftell(file);
    fseek(file, 0, 2);
    endPosition = ftell(file);
    fseek(file, currentPosition, 0);
    return endPosition;
}

struct frame {
    uint8_t bytes[535];
};

struct spectralFrame {
    uint8_t bytes[512];
};

struct spectralFrameWord {
    uint16_t words[256];
};

int main() {
    char *filePath = "C:\\Payload\\Untitled.bin";
    uint8_t *fileBuffer;
    FILE *file = NULL;
    file = fopen(filePath, "rb");
/*  if((file = fopen(filePath, "rb")) == NULL)
        cout << "Failure." << endl;
    else
        cout << "Success." << endl;
*/
    long fileSize = getFileSize(file);
    fileBuffer = new uint8_t[fileSize];
    fread(fileBuffer, fileSize, 1, file);
    fclose (file);
    long frameCount = fileSize / 535;
    frame *frames = new frame[frameCount];
    for(int i = 0, j = 0, k = 0; i < fileSize; i++) {
        frames[j].bytes[k++] = fileBuffer[i];
        if((i % 534) == 0) {
            j++;
            k = 0;
        }
    }
    delete fileBuffer;
    fileBuffer = NULL;
    spectralFrame *spectralFrames = new spectralFrame[frameCount];
    for(int i = 0; i < frameCount; i++) {
        for(int j = 22, k = 0; j < 534; j++) {
            spectralFrames[i].bytes[k++] = frames[i].bytes[j];
        }
    }
    delete frames;
    frames = NULL;
    spectralFrameWord *spectralFrameWords = new spectralFrameWord[frameCount];
    uint16_t word;
    for(int i = 0; i < frameCount; i++) {
        for(int j = 0, k = 0; i < 511;) {
            word = spectralFrames[i].bytes[j++] << 8;
            spectralFrameWords[i].words[k++] = word | spectralFrames[i].bytes[j++];
        }
    }
    delete spectralFrames;
    spectralFrames = NULL;
    filePath = "C:\\Payload\\Untitled.tsv";
    file = fopen(filePath, "w");
/*  if((file = fopen(filePath, "w")) == NULL)
        cout << "Failure." << endl;
    else
        cout << "Success." << endl;
*/
    for(int i = 0; i < 256; i++) {
        fprintf (file, "%u\t%u\n", i, spectralFrameWord[0].words[i]);
    }
    fclose (file);
    return 0;
}
#包括
#包括
使用名称空间std;
长getFileSize(文件*文件){
长电流位置,结束位置;
currentPosition=ftell(文件);
fseek(文件,0,2);
endPosition=ftell(文件);
fseek(文件,当前位置,0);
返回端位置;
}
结构框架{
uint8_t字节[535];
};
结构谱框架{
uint8_t字节[512];
};
结构谱框架词{
uint16_t字[256];
};
int main(){
char*filePath=“C:\\Payload\\Untitled.bin”;
uint8_t*文件缓冲区;
FILE*FILE=NULL;
file=fopen(文件路径,“rb”);
/*if((file=fopen(filePath,“rb”))==NULL)
你能写吗

spectralFrameWord[0].words
但是意味着

spectralFrameWords[0].words
编辑者说得再清楚不过了。它说:

“.words”的左侧必须具有类/结构/联合

这就告诉你检查
单词左边的部分,看看为什么它不符合账单


当您使用
newsometype[…]进行分配时
必须取消分配
delete[]
。使用
std::vector
可能更合适。

spectralFrameWord[0].words
但是意味着

spectralFrameWords[0].words
编辑者说得再清楚不过了。它说:

“.words”的左侧必须具有类/结构/联合

这就告诉你检查
单词左边的部分,看看为什么它不符合账单



当您使用
newsometype[…]
进行分配时,您必须取消分配
delete[]
。使用
std::vector
可能更合适。

我认为有一个输入错误。至少在这里而不是

for(int i = 0; i < 256; i++) {
    fprintf (file, "%u\t%u\n", i, spectralFrameWord[0].words[i]);
}
for(int i=0;i<256;i++){
fprintf(文件“%u\t%u\n”,i,spectralFrameWord[0].words[i]);
}
应该是

for(int i = 0; i < 256; i++) {
    fprintf (file, "%u\t%u\n", i, spectralFrameWords[0].words[i]);
}
for(int i=0;i<256;i++){
fprintf(文件“%u\t%u\n”,i,spectralFrameWords[0]。words[i]);
}

使用仅在一个符号上不同的名称是一种非常糟糕的做法。

我认为这是一种拼写错误。至少在这里不是

for(int i = 0; i < 256; i++) {
    fprintf (file, "%u\t%u\n", i, spectralFrameWord[0].words[i]);
}
for(int i=0;i<256;i++){
fprintf(文件“%u\t%u\n”,i,spectralFrameWord[0].words[i]);
}
应该是

for(int i = 0; i < 256; i++) {
    fprintf (file, "%u\t%u\n", i, spectralFrameWords[0].words[i]);
}
for(int i=0;i<256;i++){
fprintf(文件“%u\t%u\n”,i,spectralFrameWords[0]。words[i]);
}

使用仅在一个符号上不同的名称是一种非常糟糕的做法。

显示错误中引用的行(77和22,以及上下文中的周围行)。显示错误中引用的行(77和22,以及上下文中的周围行)。