对象实例化、字符串的使用方法

1、

网站设计制作过程拒绝使用模板建站;使用PHP+MYSQL原生开发可交付网站源代码;符合网站优化排名的后台管理系统;成都做网站、成都网站制作、成都外贸网站建设收费合理;免费进行网站备案等企业网站建设一条龙服务.我们是一家持续稳定运营了十余年的创新互联网站建设公司。

#include 
#include
using namespace std;
class Coordinate//类定义 类名
{  public://公共。公开
int x;
int y;
  void printx()
  {
	  cout<x=234; 
	p->y=300;
	p->printx();
	p->printy();
	delete p;//释放内存
	p=NULL;//p置空
	system("pause");
        return 0;
}

运行结果:

对象实例化、字符串的使用方法

2、字符串的使用方法:

对象实例化、字符串的使用方法

#include 
#include
#include//字符串及其相关函数包含 必须加  否则无法识别相关函数
using namespace std;
int main(void)
{  
string name;//一个字符串变量
cout<<"please input your name "<

运行结果

对象实例化、字符串的使用方法

3、小练习

#include 
#include
#include 
using namespace std;

/**
  * 定义类:Student
  * 数据成员:名字、年龄
  */
class student
{
public:
    string m_strName;//定义数据成员名字 m_strName 和年龄 m_iAge
    int  m_iAge;
    
};

int main()
{
    student stu;//Student对象stu
    
    // 设置对象的数据成员
    stu.m_strName = "慕课网";//从栈实例化对象
    stu.m_iAge = 2;
    
    // 通过cout打印stu对象的数据成员
    cout << stu.m_strName << " " << stu.m_iAge<< endl;
	system("pause");
    return 0;
}

运行结果:

对象实例化、字符串的使用方法


网站题目:对象实例化、字符串的使用方法
网址分享:http://pwwzsj.com/article/psgshi.html