简体   繁体   中英

C++ : How to substitute structure member type string

I want my string to comprised of blanks too. So I used getline not cin . I want to substitute SearchStd->StdName to NewName. So I used strcpy. But I can't do that because string type isn't char array. So I want to know what should I replace strcpy with, to substitute string type of structure member.

struct Subject {    //과목 정보 
string SubName; //과목 이름 
int Hakjum;         //과목 학점 
char Grade[10];     //과목 평점 
float GPA;          // 과목 평점
};

struct Student {    //학생 정보 
string StdName; //학생 이름 
int Hakbun;         //학번 
Subject *Sub;       //과목 
int SubNum;         //과목 수 
float AveGPA;       //교과목 평균
};

void ModifyStdInfo(Student *pSt, int StudentNum){           //학생 정보 수정
Student* SearchStd;
SearchStd = StdSearch(pSt, StudentNum);
if(SearchStd != NULL){
    string NewName;
    int NewHakbun=0;
    cout<<"* ("<<SearchStd->StdName<<", "<<SearchStd->Hakbun<<")의 정보를 수정하세요\n";
    cout<<"이름 :";
    getline(cin, NewName);
    cout<<NewName<<endl;
    strcpy((*SearchStd).StdName, NewName);
    cout<<"학번 : ";
    cin>>NewHakbun;
    SearchStd->Hakbun=NewHakbun;
}
}

You can use operator= to copy std::string .

(*SearchStd).StdName = NewName;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM