#include<iostream>
#include <ctime>
#include<string>
using namespace std;
class People{
public:
string name;
int age;
string getName();
int getAge();
void setName(string name);
void setAge(int age);
};
int People::getAge(){
return age;
}
void People::setAge(int ages){
age = ages;
}
string People::getName(){
return name;
}
void People::setName(string names){
name = names;
}
void main()
{
People peo;
peo.setAge(10);
peo.setName("123");
cout << peo.getName()<<endl;
cout << peo.getAge()<<endl;
}
在使用字符串string 时,须加上头文件 否则会报错
#include<string>
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or
there is no acceptable conversion)
|