Compiler error: memset was not declared in this scope

前端 未结 2 1512
-上瘾入骨i
-上瘾入骨i 2020-12-12 15:27

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

I am getting this error:

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


        
相关标签:
2条回答
  • 2020-12-12 16:03

    Whevever you get a problem like this just go to the man page for the function in question and it will tell you what header you are missing, e.g.

    $ 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's generally preferable to use the proper equivalent C++ headers, <cstring>/<cstdio>/<cstdlib>/etc, rather than C's <string.h>/<stdio.h>/<stdlib.h>/etc.

    0 讨论(0)
  • 2020-12-12 16:07

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

    0 讨论(0)
提交回复
热议问题