string char[] char*

C++中的string与char[]、char*详解_c++ string char*-CSDN博客 https://blog.csdn.net/m0_37433111/article/details/107347101

 

#ifndef _Person_H
#define _Person_H
class person
{
    char* name;
    int id;

public:
    void set(char*,int);
    void getdetails();
};
#endif

 

 

#include <iostream>
#include "person.h"
void person::set(char* c, int i)
{
    name = c;
    id = i;
};
void person::getdetails()
{
    std::cout << person::id << person::name << "ok person" << std::endl;
}

 

    person p;
    char a[] ="abc";
    p.set(a,123);
    p.getdetails();

 

 

 

 

 

 

posted @ 2023-12-21 20:21  papering  阅读(4)  评论(0编辑  收藏  举报