-3

我正在用 C++ 编写程序。当我使用该strlen功能时,它用红线划线。尽管该项目的构建没有错误。这就是我使用此功能的方式。(顺便说一句,strcpy也有下划线)。

Exception::Exception(int _Line, char* _File, char* _Func, char* _Desc)
{
  Line = _Line;
  int size = strlen(_File) + 1;
  File = new char[size];
  strcpy(File, _File);
  Func = new char[size];
  strcpy(Func, _Func);
  Desc = new char[size];
  strcpy(Desc, _Desc);
}

<cstring>在文件的开头声明了库。请告诉我如何解决这个问题?

4

2 回答 2

1

在 VS 编辑器中为代码加下划线的系统称为 IntelliSense,它不使用与编译器本身相同的代码(或者至少几年前我上次使用它时没有使用相同的代码)。有时它会感到困惑。

尝试std::strlen重新组织代码、包含或其他内容。

于 2020-03-20T19:55:06.713 回答
1

正如您在文档中strlen()所读到的, ,strlen()定义在 中string.h,C++ 对应std::strlen()的定义在cstring.

因此,要摆脱错误曲线,请尝试添加上述标题之一。

#include <cstring>
...
std::strlen()
于 2021-06-30T12:09:03.870 回答