首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

新手:怎么将对象中私有成员的字符串变量输出?(勿喷…)

2013-03-16 
新手求救:如何将对象中私有成员的字符串变量输出??(勿喷……)#includeiostreamusing namespace stdclass

新手求救:如何将对象中私有成员的字符串变量输出??(勿喷……)

#include<iostream>
using namespace std;
class Owner{
private:
string name;
string sex;
int age;
string career;
public:
Owner(string n,string s,int a,string c);
void show();
};
Owner::Owner(string n,string s,int a,string c){
name = n;
sex = s;
age = a;
career = c;
}
void Owner::show(){
cout<<name;//这里出错……

}

void main(){
Owner a("weiwei","men",22,"college student");
a.show();
}
[解决办法]
加上#include <string>头文件既可

热点排行