||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===| D:\Programming\Algorithm\Test\main.cpp||In function 'int main()':| D:\Programming\Algorithm\Test\main.cpp|11|error: 'exit' was not declared in this scope| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
时间: 2023-07-19 21:36:27 浏览: 446
这个错误提示是因为程序中使用了 `exit()` 函数,但是没有包含相应的头文件。`exit()` 函数定义在 `stdlib.h` 头文件中,因此需要在程序开头加上 `#include <stdlib.h>`。修改后的代码如下:
```c
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
int main() {
int fid;
fid = open("./test.txt", O_RDWR | O_CREAT, 0644);
if (fid == -1) {
perror("open or create error");
exit(0);
}
close(fid);
return 0;
}
```
重新编译运行,应该就不会出现这个错误了。
阅读全文
相关推荐


















