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

问题描述 投票:-5回答:1

我是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;
 }

我的第一个错误出现在构造函数的行上,复制infoPersonne :: infoPersonne(infoPersonne&ip)在特定行std :: string nom = ip.nom。 ERROR IS:从'char * [40]'转换为非标量类型'std :: string {aka std :: basic_string}''我有另一个错误:'class infoPersonne'没有名为'nt'的成员,但成员nt是否定义了?第三个是:请求'A'中的成员'affiche',这是非类型'infoPersonne()'|

你能帮我吗 ?先感谢您。

c++ stdstring
1个回答
-1
投票

对于初学者来说,std :: strings比char数组更容易使用。除非有理由不这样做,否则我建议你使用它们。

代码有很多问题。看看你是否可以先获得更少的代码。如何从main调用一个函数,传入stings和char数组指针,这样你就可以降低该技能。

© www.soinside.com 2019 - 2024. All rights reserved.