我正在尝试用Ubuntu 9.10 (gcc 4.4.1)编译我的C程序。
我得到了这个错误:
Rect.cpp:344: error: ‘memset’ was not declared in this scope
但问题是我已经在我的cpp文件中包含了:
#include <stdio.h>
#include <stdlib.h>
同样的程序在Ubuntu 8.04 (gcc 4.2.4)下编译得很好。
请告诉我我漏掉了什么。
发布于 2010-03-24 12:40:26
您应该包含<string.h>
(或其C++等效项<cstring>
)。
发布于 2010-03-24 15:40:32
无论什么时候你遇到这样的问题,只要转到有问题的man page for the function,它就会告诉你你遗漏了什么标题,例如
$ 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);
请注意,与C的<string.h>
/<stdio.h>
/<stdlib.h>
/etc.相比,对于C++,通常更可取的是使用适当的等效C++标头<cstring>
/<cstdio>
/<cstdlib>
/etc,
https://stackoverflow.com/questions/2505365
复制相似问题