[Error] 'memset' was not declared in this scope
时间: 2023-10-16 10:10:06 浏览: 27
这个错误通常是因为你没有包含 `cstring` 头文件。`memset` 函数的原型定义在该头文件中。
你可以在代码中添加以下语句来包含该头文件:
```c++
#include <cstring>
```
如果你已经包含了该头文件,那么可能是编译器版本问题。在某些较旧的编译器中,`memset` 函数可能需要额外的头文件支持。你可以尝试包含以下头文件:
```c++
#include <string.h>
```
如果问题仍然存在,你可以尝试更新编译器版本。
相关问题
‘memset’ was not declared in this scope
This error message indicates that the compiler cannot find a declaration for the function 'memset' in the current scope.
To fix this error, you need to include the header file that declares the 'memset' function. In C++, this header file is <cstring>, so you should add the following line at the top of your source code file:
```#include <cstring>```
This will tell the compiler to include the declaration of the 'memset' function, which should resolve the error.
12 20 C:\Users\王淑婧\Desktop\贪吃蛇.cpp [Error] 'srand' was not declared in this scope13 34 C:\Users\王淑婧\Desktop\贪吃蛇.cpp [Error] 'memset' was not declared in this scope68 39 C:\Users\王淑婧\Desktop\贪吃蛇.cpp [Error] 'Sleep' was not declared in this scope
这是因为你的代码中没有包含对应的头文件导致的。你需要在代码开头添加以下三个头文件:
```c++
#include <cstdlib>
#include <cstring>
#include <windows.h>
```
其中,`cstdlib` 包含了 `srand` 函数,`cstring` 包含了 `memset` 函数,`windows.h` 包含了 `Sleep` 函数。添加之后再编译就可以解决这些错误了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)