【问题标题】:Request for member of non-class type请求非类成员
【发布时间】:2013-07-23 03:10:07
【问题描述】:

我正在尝试将 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();
        }

我真的很茫然。

【问题讨论】:

  • 使用 std::string: password(word)
  • C 字符串没有成员。
  • 也许你的意思是passwrd.assign(word);

标签: c++


【解决方案1】:

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

【讨论】:

  • 啊,没错,我把它当作一个字符串类而不是一个 C 字符串
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2019-04-28
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    相关资源
    最近更新 更多