"underscore in number " 这个报错是什么原因啊

handaochang 2010-06-23 02:47:12
1 #include <unistd.h>
2 #include <stdlib.h>
3
4 int main(void)
5 {
6 int fd;
7
8 fd = open("log.txt",0_WRONLY);
9 close(fd);
10 return 0;
11 }


编译的时候不能通过提示 “underscore in number"

...全文
208 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
handaochang 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 oyster2008 的回复:]

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
[/Quote]
嗯 嗯 就是这个
刚看了一下 manpage ,看来以后有这种问题还是要先自己查手册
贴一小段给大家看下吧
--------------------------------------

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);

DESCRIPTION
The open() system call is used to convert a pathname into a file
descriptor (a small, non-negative integer for use in subsequent I/O as
with read, write, etc.). When the call is successful, the file
descriptor returned will be the lowest file descriptor not currently
open for the process. This call creates a new open file, not shared
with any other process. (But shared open files may arise via the
fork(2) system call.) The new file descriptor is set to remain open
across exec functions (see fcntl(2)). The file offset is set to the
beginning of the file.

The parameter flags is one of O_RDONLY, O_WRONLY or O_RDWR which
request opening the file read-only, write-only or read/write, respec-
tively, bitwise-or’d with zero or more of the following:
zhangweiit 2010-06-23
  • 打赏
  • 举报
回复
underscore in number
这个消息从字面上就要反应过来了出在0_这个下划线
那肯定是这个常量没被定义
handaochang 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 icesky_ff 的回复:]

缺少头文件吧
[/Quote]
谢啦,是缺少头文件
我一直以为是在 unistd.h 这个头里边呢

原来是少了 fcntl.h
oyster2008 2010-06-23
  • 打赏
  • 举报
回复
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

icesky_ff 2010-06-23
  • 打赏
  • 举报
回复
#include <fcntl.h>
加上试试吧
icesky_ff 2010-06-23
  • 打赏
  • 举报
回复
缺少头文件吧
handaochang 2010-06-23
  • 打赏
  • 举报
回复

我开始写的是大写的 字母 o

但是也是会报错啊

报“O_WRONLY" undeclared"
oyster2008 2010-06-23
  • 打赏
  • 举报
回复
fd = open("log.txt",0_WRONLY);
把零改成大写的o
icesky_ff 2010-06-23
  • 打赏
  • 举报
回复
“0_WRONLY”前边是0,还是o啊
handaochang 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dinjay 的回复:]

open是什么函数?fopen吧
File *file=fopen("log.txt","r");
fclose(file);
[/Quote]
是unbuffered I/O 函数,是UNIX标准的一部分
不是标准c的函数
dinjay 2010-06-23
  • 打赏
  • 举报
回复
open是什么函数?fopen吧
File *file=fopen("log.txt","r");
fclose(file);

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧