我试图在Ubuntu 9.10(gcc 4.4.1)中编译我的C程序.
我收到此错误:
Rect.cpp:344: error: ‘memset’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
但问题是我已经包含在我的cpp文件中:
#include <stdio.h>
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
同样的程序在Ubuntu 8.04(gcc 4.2.4)下编译得很好.
请告诉我我错过了什么.
Pau*_*l R 129
如果您遇到这样的问题,只需转到相关功能的手册页,它会告诉您缺少哪个标题,例如
$ man memset
MEMSET(3) BSD Library Functions Manual MEMSET(3)
NAME
memset -- fill a byte string with a byte value
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <string.h>
void *
memset(void *b, int c, size_t len);
Run Code Online (Sandbox Code Playgroud)
请注意,对于C++,通常最好使用适当的等效C++头文件,<cstring>/ <cstdio>/ <cstdlib>/ etc,而不是C的<string.h>/ <stdio.h>/ <stdlib.h>/ etc.