请求非类类型的成员

Request for member of non-class type

本文关键字:成员 类型 请求      更新时间:2023-10-16

我正试图将一个C字符串保存到我的Password类的实例中,但我一直收到错误消息

请求"Password::Password"中的成员"assign",该成员属于非类类型"char[80]"

以下是与错误有关的代码部分:

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
class Password
{
    const static string too_short;
    const static string no_upper;
    const static string no_lower;
    const static string no_digit;
    const static string no_punct;
    string end_message;
    int score;
    char password[80];
    string passwrd;
    public:
        Password (char word[])
        {
            password.assign(word);
            c_stringCheck();
        }

我真的不知所措。

字符数组没有方法,但您正试图在一个方法上调用assign。也许可以使用strcpystrncpy、非标准的strlcpy或惯用的C++等价物。

密码只是一个char数组。所以你不能全部使用password.assign()函数。试试strcpy!