【问题标题】:error C3861: 'strcpy_y': identifier not found错误 C3861:“strcpy_y”:未找到标识符
【发布时间】:2014-01-15 03:08:59
【问题描述】:
Pacient& operator = ( Pacient&p) {
  cout << "Operator = Pacient" << endl;
  delete [] this->nume;
  this->nume = new char[strlen(p.nume)+1];
  strcpy_y(this->nume,strlen(p.nume)+1,p.nume); // ERROR
  delete [] this->prenume;
  this->prenume = new char[strlen(p.prenume)+1];
  strcpy_y(this->prenume,strlen(p.prenume)+1,p.prenume); // ERROR
  this->varsta = p.varsta;
  return *this;
}

1>正在编译...
1>pacienti.cpp
1>f:\bob\facultate\semestrul iii\programareorientataobiect\proiect pacienti\proiect\proiect\pacienti.cpp(24):错误 C3861:'strcpy_y':找不到标识符
1>f:\bob\facultate\semestrul iii\programareorientataobiect\proiect pacienti\proiect\proiect\pacienti.cpp(27):错误 C3861:'strcpy_y':找不到标识符

我收到此错误。为什么?我应该怎么做才能摆脱它?

【问题讨论】:

  • strcpy_y 到底是什么?
  • 我假设strncpy。要么那个要么strcpy_s
  • 在这里使用 std::string 可以省去很多麻烦

标签: c++ visual-c++ c++11


【解决方案1】:

编译器不知道strcpy_y 是什么,因为您没有在当前翻译单元中该行之前的任何地方声明它。

要么提供 strcpy_y 的声明(例如 #include 相关的标头,要么转发声明它),或者如果您打算调用其他函数,请修正拼写错误。

【讨论】:

    【解决方案2】:

    没有strcpy_y 这样的东西,至少在标准 C++ 中没有。

    也许你的意思是strcpy_sfrom WINAPI

    如果strcpy_y是你自己创建的函数,那么你需要#include声明它的文件。

    为什么首先使用原始 C 风格的字符串?只需使用分配的std::string 作为定位变量,所有这些问题都会消失。使用operator=复制strings。

    【讨论】:

    • 非常感谢!它是 strcpy_s :D
    【解决方案3】:

    我认为它可以帮助你: #include &lt;string.h&gt;

    但我不建议在您的代码中使用 strcpy_y,因为它不是 C++。

    【讨论】:

    • 哦,我的错误。我以为我们在谈论 strcpy_s。
    猜你喜欢
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    相关资源
    最近更新 更多