Compiler error: memset was not declared in this scope

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

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 

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

#include  #include 

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

Please tell me what am I missing.

回答1:

You should include (or its C++ equivalent, ).



回答2:

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        void *      memset(void *b, int c, size_t len); 

Note that for C++ it's generally preferable to use the proper equivalent C++ headers, ///etc, rather than C's ///etc.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!