STRCPY 是未定义的 C++

And*_*oom -1 strcpy strncpy

我试图实现 strcpy 或 strncpy 并且无论我使用哪个都显示错误。

错误仅在 strncpy 和 strcpy 下

项目.cpp:

#include "Item.h"
#include <iomanip>
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
#include "Date.h"
#include "POS.h"
#include "PosIO.h"

namespace sict {
    Item::Item(){
         _name = '\0';
         _price = 0;
         _taxed ='0';
         _quantity = '\0';
    }

    Item::Item(const char* sku,  const char * name, double price, bool taxed){

        strNcpy(_sku, sku, MAX_SKU_LEN);

         name = new char[20];
        strcpy(_name, name);

        _quantity = 0;
        price = _price;
        if (price = '\0') {
            _taxed = true;
        }
    }
    void Item::sku(const char* value){
        strncpy(_sku, value);

    }
    void Item::price(double p){
        p = _price;
    }
    void Item::name(const char * n){
        strcpy(_name, n);

    }



}
Run Code Online (Sandbox Code Playgroud)

知道如何修复它,我从 item.cpp 中排除了很多无关紧要的代码。

eml*_*lai 7

双方strcpystrncpy在声明cstring头。您需要包含它才能使用以下功能:

#include <cstring>
Run Code Online (Sandbox Code Playgroud)