Compiler Error: memset has not been declared in this area

I am trying to compile my C program in Ubuntu 9.10 (gcc 4.4.1).

I get this error:

Rect.cpp:344: error: 'memset' was not declared in this scope 

But the problem is that I already included cpp in my file:

 #include <stdio.h> #include <stdlib.h> 

And the same program compiles under Ubuntu 8.04 (gcc 4.2.4).

Please tell me what I am missing.

+78
c ++ gcc
Mar 24 '10 at 4:38
source share
2 answers

You must include <string.h> (or its C ++ equivalent, <cstring> ).

+133
Mar 24 '10 at 4:40
source share

You have such a problem, just go to the man page for this function and it will tell you which header is missing, for example

 $ 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); 

Note that for C ++, it is usually preferable to use the corresponding equivalent C ++ headers, <cstring> / <cstdio> / <cstdlib> / etc, rather than C <string.h> / <stdio.h> / <stdlib.h> / etc.

+112
Mar 24 '10 at 7:40
source share



All Articles