First, the definition is initialized
Second, common operation
Instance:
1#include <stdlib.h>2#include <iostream>3#include <string>4 using namespacestd;5 classStudent6 {7 Public:8 voidSetName (string_name)9 {TenM_strname=_name; One A } - stringGetName () - { the returnM_strname; - } - voidSetgender (string_gender) - { +M_strgender=_gender; - + } A stringGetgender () at { - returnM_strgender; - } - intGetscore ()//int represents his return value. - { - in returnM_iscore; - } to voidInitscore () + { -M_iscore=0; the } * voidStudyint_score) $ {Panax Notoginsengm_iscore+=_score; - } the Private: + stringM_strname; A stringM_strgender; the intM_iscore; + }; - intMainvoid) $ { $ Student Stu; -Stu.initscore ();//Initialize the credits -Stu.setname ("David Han"); theStu.setgender ("male"); -Stu.study ( -);WuyiCout<<stu.getname () <<endl<<stu.getgender () <<endl<<stu.getscore () <<endl;//Be sure to add parentheses here, because the parentheses are the function theSystem"Pause"); - return 0; Wu}
11c++ string manipulation