‘strcpy’ was not declared in this scope

今天做c++,作业。用到了strcpy
我已经使用了这个头文件(c++程序设计那本书里面说的需要的)

#include<string>
AI写代码
cpp
运行
1
但是报错
error: ‘strcpy’ was not declared in this scope
然后
我在网上找到了结果
解决方法:
一:只使用一个头文件

#include <cstring >
AI写代码
cpp
运行
1
二:使用两个头文件

#include <string>
#include <string.h>

总结:

#include <string.h> 在c++中,是指标准化以前的标准c库中的字char*字符串处理函数

#include <string>中在1988年标准化以后,c++中含的STL的string容器

#include <cstring> 是在1988年标准化以后,<string.h>的演变。

总之你记住一句话:<string>与<string.h>是完全不同的两个东西。

posted @ 2026-02-14 00:05  师大无雨  阅读(1)  评论(0)    收藏  举报