此错误的含义是什么:从 'char* [40] 转换为非标量类型 'std::string



我是CPP编程的新手,我正在与必须包含一个名称的课程,性别,年龄和电话号码。

我有三个错误。

有我的程序:

enter code here
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class infoPersonne
{
   char *nom [40];
   char *sexe;
   int age;
   char *notel [12];
   public:
      infoPersonne(char * , char *, int , char *);
      infoPersonne();
      infoPersonne(infoPersonne &ip);
      ~infoPersonne();
      void affiche();
};

infoPersonne::infoPersonne(char *n, char *s, int a, char *nt) // contructeur
{
    std::string nom=n;
    std::string sexe=s;
    age=a;
    std::string notel=nt;
    cout<< "construction de l'information d'une personne"<<endl;
}
infoPersonne::infoPersonne( infoPersonne &ip) // constructeur par recopie
{
    std::string nom  = ip.nom;  
    std::string sexe = ip.sexe;
    age=ip.age;
    std::string notel=ip.nt;
 }
 infoPersonne::infoPersonne() // constructeur par défaut
 {
     std::string nom  = "";
     std::string sexe = "";
     age = 0;
     std::string notel = "0";
 }
 infoPersonne:: ~infoPersonne() // destructeur
 {
     cout<<"destruction de l'information d'une personne"<<endl;
     delete []nom;
     delete sexe;
     delete []notel;
 }
 void infoPersonne:: affiche()
 {
     cout << endl << "Nom  :" << nom
          << endl << "Sexe :" << sexe
          << endl << "Age  :" << age
          << endl << "Telephone : " << notel << endl;
 }

using namespace std;
int main(int argc, char *argv[])
{
    infoPersonne A();
    infoPersonne B("Louise Messier","F",54, "514-756-8890");
    A.affiche();
    B.affiche();
    system("PAUSE");
    return EXIT_SUCCESS;
 }

我的第一个错误出现在copy infopersonne :: infopersonne(infopersonne&amp; ip)的构造函数上,该行std :: string nom = ip.nom。错误是:从'char* [40]'转换为非量表类型'std :: string {aka std :: basic_string}'请求|而且我还有另一个错误:" class infopersonne"没有成员命名为" nt",但nt成员是定义的吗?第三个是:在" a"中要求成员'effiche'的请求,该请求是非类型'infopersonne()'|的请求。

你能帮我吗?先感谢您。

std :: strings使用比初学者的char数组更容易使用。我建议您使用它们,除非有理由不这样做。

代码有很多问题。看看您是否可以首先获得更少的代码。您从Main呼叫的一个功能如何,传递刺和字符阵列指针,以便您可以降低该技能。

最新更新