2013-07-23 118 views
0

我想一個C字符串保存到我的密碼類的實例,我不斷收到錯誤消息申請非類類型的成員

request for member 'assign' in 'Password::password', which is of non-class type '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(); 
     } 

我真的很茫然。

+0

使用'std :: string'和':password(word)'。 – chris

+0

C字符串沒有成員。 – Rapptz

+0

也許你的意思是'passwrd.assign(word);'。 –

回答

0

字符數組沒有方法,但您試圖在一個上調用assign。也許使用strcpy,strncpy,非標準strlcpy,或者使用習慣C++等效。

+0

ahhh多數民衆贊成是正確的,我把它當作一個字符串類而不是一個C字符串 – BKreger

0

密碼只是一個字符數組。 所以你不能所有的password.assign()函數。 嘗試strcpy!

相關問題