C++ char(头文件)之前的预期主表达式

C++ expected primary-expression before char (header file)

本文关键字:表达式 char 文件 C++      更新时间:2023-10-16

ISBN.h

int isValid(const char str[]);
int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[]); 

错误:

ISBN.h:2:18: error: FILE was not declared in this scope
ISBN.h:2:24: error: fp was not declared in this scope
ISBN.h:2:28: error: expected primary-expression before const
ISBN.h:2:46: error: expected primary-expression before char
ISBN.h:2:59: error: expected primary-expression before char
ISBN.h:2:77: error: expected primary-expression before char
ISBN.h:2:89: error: expression list treated as compound expression in initializer [-fpermissive]   

不确定我是否理解该错误,因为我有另一个具有相同类型参数的头文件,不会产生任何错误:

国际标准书号(ISBN)修复.h

FILE* open(const char filename[]);
int isRegistered(FILE* fp, int area);
int minNoDigits(FILE* fp, int area);
int isRegistered(FILE* fp, int area, const char publisher[]);
int close(FILE* fp);
  1. 这些功能原型是我们的教授给我们的。
  2. isRegistered 被定义三次,但参数数量不同,所以当你在 main 中使用 X 个参数的函数时,它会只使用带有所述参数的相应版本吗?
  3. 我收到与我的ISBN.cpp对应的第二组错误,其中包括我的ISBN.h

    ISBN.cpp: In function int isRegister(FILE*, const char*, char*, char*, char*):ISBN.cpp:36:89:错误:int isRegister(FILE*, const char*, char*, char*, char*) 重新声明为不同类型的符号ISBN.h:2:5:错误:先前的 int 声明已注册

国际标准书号.cpp

#include "ISBN.h"
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;
int isValid(const char str[])
{
}
int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[])
{
} 

FILE<cstdio> 标头的一部分,在开始在标头中使用它之前,不会包含该标头。这就像您必须如何#include <iostream>才能使用std::cout。您通常应该在每个文件的基础上包含所需的每个标头,而不是依赖其他文件来包含它们。

需要注意的另一件事是,您通常应该先处理第一个列出的错误。一个错误可能会导致无意义的错误的连锁反应,最终很容易使您偏离轨道。