error: 'EOF' was not declared in this scope的解决办法

本文详细介绍了在使用COOOL优化库升级到MinGW4.4.0编译时遇到的错误,并提供了相应的解决方法。通过在报错文件的最开始加入#include<stdio.h>,解决了EOF、stderr、putc等未声明的问题。


error: 'EOF' was not declared in this scope的解决办法

  (2012-06-04 13:35:45)
标签: 

error

 

eof

 

stderr

 

putc

 

stdio

 

was

 

not

 

declared

 

in

 

this

 

scope

it

分类: C++

将COOOL优化库升级到MinGW 4.4.0编译,结果报错:

error: 'EOF' was not declared in this scope

error: 'stderr' was not declared in this scope

error: 'putc' was not declared in this scope

解决方法是在报错文件的最开始加上#include <stdio.h>,因为EOF、stderr等都是在这个文件中定义的。

#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 256 void readFile(const char *filename, char lines[][MAX_LINE], int *lineCount) { FILE *file = fopen(filename, "r"); if (file == NULL) { printf("Error: Could not open file %s\n", filename); return; } *lineCount = 0; while (fgets(lines[*lineCount], MAX_LINE, file) != NULL && *lineCount < 100) { (*lineCount)++; } fclose(file); } void writeFile(const char *filename, const char *content) { FILE *file = fopen(filename, "a"); if (file == NULL) { printf("Error: Could not open file %s\n", filename); return; } fprintf(file, "%s\n", content); fclose(file); } typedef struct QueueNode { char data[MAX_LINE]; struct QueueNode *next; } QueueNode; typedef struct { QueueNode *front, *rear; } LinkQueue; void initQueue(LinkQueue *queue) { queue->front = queue->rear = NULL; } void enqueue(LinkQueue *queue, const char *data) { QueueNode *newNode = (QueueNode *)malloc(sizeof(QueueNode)); strcpy(newNode->data, data); newNode->next = NULL; if (queue->rear == NULL) { queue->front = queue->rear = newNode; } else { queue->rear->next = newNode; queue->rear = newNode; } } char* dequeue(LinkQueue *queue) { if (queue->front == NULL) { return NULL; } QueueNode *temp = queue->front; char *data = strdup(temp->data); queue->front = queue->front->next; if (queue->front == NULL) { queue->rear = NULL; } free(temp); return data; } #define MAX_SIZE 100 typedef struct { char data[MAX_SIZE][MAX_LINE]; int length; } SeqList; void initSeqList(SeqList *list) { list->length = 0; } void insertSeqList(SeqList *list, const char *data) { if (list->length >= MAX_SIZE) { printf("Error: Sequence list is full.\n"); return; } strcpy(list->data[list->length++], data); } int searchSeqList(SeqList *list, const char *key) { for (int i = 0; i < list->length; i++) { if (strcmp(list->data[i], key) == 0) { return i; } } return -1; } #define TABLE_SIZE 10 typedef struct HashNode { char key[MAX_LINE]; struct HashNode *next; } HashNode; typedef HashNode *HashTable[TABLE_SIZE]; unsigned int hashFunction(const char *key) { unsigned int hash = 0; for (int i = 0; key[i] != '\0'; i++) { hash = hash * 31 + key[i]; } return hash % TABLE_SIZE; } void initHashTable(HashTable table) { for (int i = 0; i < TABLE_SIZE; i++) { table[i] = NULL; } } void insertHashTable(HashTable table, const char *key) { unsigned int index = hashFunction(key); HashNode *newNode = (HashNode *)malloc(sizeof(HashNode)); strcpy(newNode->key, key); newNode->next = table[index]; table[index] = newNode; } char* searchHashTable(HashTable table, const char *key) { unsigned int index = hashFunction(key); HashNode *node = table[index]; while (node != NULL) { if (strcmp(node->key, key) == 0) { return node->key; } node = node->next; } return NULL; } int main() { // 初始化数据结构 LinkQueue queue; initQueue(&queue); SeqList seqList; initSeqList(&seqList); HashTable hashTable; initHashTable(hashTable); // 读取订单文件 char orders[100][MAX_LINE]; int orderCount = 0; readFile("order.txt", orders, &orderCount); // 处理订单 for (int i = 0; i < orderCount; i++) { enqueue(&queue, orders[i]); insertSeqList(&seqList, orders[i]); insertHashTable(hashTable, orders[i]); } // 写入处理结果到文件 while (1) { char *order = dequeue(&queue); if (order == NULL) { break; } writeFile("shop.txt", order); free(order); } // 查找订单 char key[MAX_LINE]; printf("Enter an order to search: "); scanf("%s", key); if (searchHashTable(hashTable, key) != NULL) { printf("Order found in hash table.\n"); } else { printf("Order not found in hash table.\n"); } return 0; }.3/1.4.3.cpp:3:5: error: redefinition of ‘int main()’ int main() ^~~~ In file included from 1.4.3/1.4.3.cpp:1:0: 1.4.3/1.4.3.h:136:5: note:int main()’ previously defined here int main() { ^~~~ 1.4.3/1.4.3.cpp:5:2: error: ‘UserList’ was not declared in this scope UserList user_list; ^~~~~~~~ 1.4.3/1.4.3.cpp:5:2: note: suggested alternative: ‘SeqList’ UserList user_list; ^~~~~~~~ SeqList 1.4.3/1.4.3.cpp:6:18: error: ‘user_list’ was not declared in this scope InitialUserList(user_list); ^~~~~~~~~ 1.4.3/1.4.3.cpp:6:18: note: suggested alternative: ‘sys_errlist’ InitialUserList(user_list); ^~~~~~~~~ sys_errlist 1.4.3/1.4.3.cpp:6:2: error:InitialUserList’ was not declared in this scope InitialUserList(user_list); ^~~~~~~~~~~~~~~ 1.4.3/1.4.3.cpp:6:2: note: suggested alternative:initSeqList’ InitialUserList(user_list); ^~~~~~~~~~~~~~~ initSeqList 1.4.3/1.4.3.cpp:7:2: error: ‘LoadUser’ was not declared in this scope LoadUser(user_list,"/data/workspace/myshixun/1.4.3/user.txt"); //读文件,将用户信息插入顺序表 ^~~~~~~~ 1.4.3/1.4.3.cpp:9:15: error: ‘UserLoginwas not declared in this scope int location=UserLogin(user_list); ^~~~~~~~~ 1.4.3/1.4.3.cpp:11:3: error: ‘User’ was not declared in this scope User user = user_list.users[location]; //获取当前登录用户对象 ^~~~ 1.4.3/1.4.3.cpp:13:3: error: ‘ShopList’ was not declared in this scope ShopList shop_list; ^~~~~~~~ 1.4.3/1.4.3.cpp:13:3: note: suggested alternative: ‘SeqList’ ShopList shop_list; ^~~~~~~~ SeqList 1.4.3/1.4.3.cpp:14:19: error: ‘shop_list’ was not declared in this scope InitialShopList(shop_list); ^~~~~~~~~ 1.4.3/1.4.3.cpp:14:19: note: suggested alternative: ‘va_list’ InitialShopList(shop_list); ^~~~~~~~~ va_list 1.4.3/1.4.3.cpp:14:3: error:InitialShopList’ was not declared in this scope InitialShopList(shop_list); ^~~~~~~~~~~~~~~ 1.4.3/1.4.3.cpp:14:3: note: suggested alternative:initSeqList’ InitialShopList(shop_list); ^~~~~~~~~~~~~~~ initSeqList 1.4.3/1.4.3.cpp:15:3: error: ‘LoadShop’ was not declared in this scope LoadShop(shop_list,"/data/workspace/myshixun/1.4.3/shop.txt"); //读文件,将商家信息插入顺序表 ^~~~~~~~ 1.4.3/1.4.3.cpp:17:3: error:InitialHashList’ was not declared in this scope InitialHashList(); ^~~~~~~~~~~~~~~ 1.4.3/1.4.3.cpp:18:3: error: ‘CreateHashList’ was not declared in this scope CreateHashList(shop_list); //利用顺序表shop_list创建散列表 ^~~~~~~~~~~~~~ 1.4.3/1.4.3.cpp:21:3: error:InitialQueue’ was not declared in this scope InitialQueue(Q); ^~~~~~~~~~~~ 1.4.3/1.4.3.cpp:21:3: note: suggested alternative:initQueue’ InitialQueue(Q); ^~~~~~~~~~~~ initQueue 1.4.3/1.4.3.cpp:22:3: error: ‘LoadQueue’ was not declared in this scope LoadQueue(Q,"/data/workspace/myshixun/1.4.3/order.txt"); //读文件,将所有订单信息插入队列 ^~~~~~~~~ 1.4.3/1.4.3.cpp:22:3: note: suggested alternative: ‘LinkQueue’ LoadQueue(Q,"/data/workspace/myshixun/1.4.3/order.txt"); //读文件,将所有订单信息插入队列 ^~~~~~~~~ LinkQueue 1.4.3/1.4.3.cpp:24:23: error: ‘user’ was not declared in this scope CreateOrderByUser(Q,user.account); //创建新的预定 ^~~~ 1.4.3/1.4.3.cpp:24:3: error: ‘CreateOrderByUser’ was not declared in this scope CreateOrderByUser(Q,user.account); //创建新的预定 ^~~~~~~~~~~~~~~~~ 1.4.3/1.4.3.cpp:25:3: error: ‘SaveOrder’ was not declared in this scope SaveOrder(Q,"/data/workspace/myshixun/1.4.3/order.txt"); //保存订单信息至文件order.txt中 ^~~~~~~~~
06-18
D:\cxdownload\kechengsheji(3).cpp|9|warning: scoped enums only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp||In function 'std::string ratingToString(Rating)':| D:\cxdownload\kechengsheji(3).cpp|19|error: 'Rating' is not a class or namespace| D:\cxdownload\kechengsheji(3).cpp|20|error: 'Rating' is not a class or namespace| D:\cxdownload\kechengsheji(3).cpp|21|error: 'Rating' is not a class or namespace| D:\cxdownload\kechengsheji(3).cpp|22|error: 'Rating' is not a class or namespace| D:\cxdownload\kechengsheji(3).cpp|36|warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|75|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|81|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|91|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp||In constructor 'Book::Book(std::ifstream&)':| D:\cxdownload\kechengsheji(3).cpp|98|error: 'readLine' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|107|error: 'stoi' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|119|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|125|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|135|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp||In constructor 'DVD::DVD(std::ifstream&)':| D:\cxdownload\kechengsheji(3).cpp|142|error: 'readLine' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|150|error: 'stoi' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|163|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|169|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp|179|warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]| D:\cxdownload\kechengsheji(3).cpp||In constructor 'Picture::Picture(std::ifstream&)':| D:\cxdownload\kechengsheji(3).cpp|186|error: 'readLine' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|194|error: 'stoi' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|218|error: 'nullptr' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp||In function 'int main()':| D:\cxdownload\kechengsheji(3).cpp|246|error: 'nullptr' was not declared in this scope| D:\cxdownload\kechengsheji(3).cpp|247|error: no matching function for call to 'Book::Book()'| D:\cxdownload\kechengsheji(3).cpp|247|note: candidates are:| D:\cxdownload\kechengsheji(3).cpp|97|note: Book::Book(std::ifstream&)| D:\cxdownload\kechengsheji(3).cpp|97|note: candidate expects 1 argument, 0 provided| D:\cxdownload\kechengsheji(3).cpp|68|note: Book::Book(const Book&)| D:\cxdownload\kechengsheji(3).cpp|68|note: candidate expects 1 argument, 0 provided| D:\cxdownload\kechengsheji(3).cpp|248|error: no matching function for call to 'DVD::DVD()'| D:\cxdownload\kechengsheji(3).cpp|248|note: candidates are:| D:\cxdownload\kechengsheji(3).cpp|141|note: DVD::DVD(std::ifstream&)| D:\cxdownload\kechengsheji(3).cpp|141|note: candidate expects 1 argument, 0 provided| D:\cxdownload\kechengsheji(3).cpp|112|note: DVD::DVD(const DVD&)| D:\cxdownload\kechengsheji(3).cpp|112|note: candidate expects 1 argument, 0 provided| D:\cxdownload\kechengsheji(3).cpp|249|error: no matching function for call to 'Picture::Picture()'| D:\cxdownload\kechengsheji(3).cpp|249|note: candidates are:| D:\cxdownload\kechengsheji(3).cpp|185|note: Picture::Picture(std::ifstream&)| D:\cxdownload\kechengsheji(3).cpp|185|note: candidate expects 1 argument, 0 provided| D:\cxdownload\kechengsheji(3).cpp|156|note: Picture::Picture(const Picture&)| D:\cxdownload\kechengsheji(3).cpp|156|note: candidate expects 1 argument, 0 provided| D:\cxdownload\kechengsheji(3).cpp|253|error: 'm' does not name a type| D:\cxdownload\kechengsheji(3).cpp|260|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|260|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|260|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|260|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|260|error: expected ')' before 'if'| D:\cxdownload\kechengsheji(3).cpp|280|error: 'm' does not name a type| D:\cxdownload\kechengsheji(3).cpp|286|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|286|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|286|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|286|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|286|error: expected ')' before 'if'| D:\cxdownload\kechengsheji(3).cpp|291|error: 'm' does not name a type| D:\cxdownload\kechengsheji(3).cpp|298|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|298|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|298|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|298|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|298|error: expected ')' before 'if'| D:\cxdownload\kechengsheji(3).cpp|304|error: 'm' does not name a type| D:\cxdownload\kechengsheji(3).cpp|312|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|312|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|312|error: expected ';' before 'if'| D:\cxdownload\kechengsheji(3).cpp|312|error: expected primary-expression before 'if'| D:\cxdownload\kechengsheji(3).cpp|312|error: expected ')' before 'if'| D:\cxdownload\kechengsheji(3).cpp|317|error: 'm' does not name a type| D:\cxdownload\kechengsheji(3).cpp|320|error: expected ';' before 'break'| D:\cxdownload\kechengsheji(3).cpp|320|error: expected primary-expression before 'break'| D:\cxdownload\kechengsheji(3).cpp|320|error: expected ';' before 'break'| D:\cxdownload\kechengsheji(3).cpp|320|error: expected primary-expression before 'break'| D:\cxdownload\kechengsheji(3).cpp|320|error: expected ')' before 'break'| D:\cxdownload\kechengsheji(3).cpp|326|error: ISO C++ forbids declaration of 'm' with no type [-fpermissive]| D:\cxdownload\kechengsheji(3).cpp|326|error: range-based 'for' loops are not allowed in C++98 mode| D:\cxdownload\kechengsheji(3).cpp|327|error: base operand of '->' is not a pointer| D:\cxdownload\kechengsheji(3).cpp|329|error: base operand of '->' is not a pointer| D:\cxdownload\kechengsheji(3).cpp|345|error: 'it' does not name a type| ||More errors follow but not being shown.| ||Edit the max errors limit in compiler options...| ||=== Build failed: 50 error(s), 11 warning(s) (0 minute(s), 1 second(s)) ===| 有这些报错改一下
06-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值