摘要: 1:在创建对象时,程序自动调用构造函数。同一个类中可以有多个构造函数,通过这样的形式创建一个CPerson对象,例如: CPerson p1(0,"jack",22,7000); CPerson p2=Cperson(1,"tony",25,8000); CPerson p; 2:利用构造函数初始化 阅读全文
posted @ 2017-09-18 21:36 一串字符串 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 1:建立一个类CPerson。 (1)在person.h文件中代码: class CPerson { public: //数据成员 int m_iIndex; char m_cName[25]; short m_shAge; double m_dSalary; //成员函数 short getAge 阅读全文
posted @ 2017-09-18 21:10 一串字符串 阅读(265) 评论(0) 推荐(0) 编辑
摘要: 1:代码如下: // 6.23.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <string> using namespace std; int main(int argc, _TCHAR* argv 阅读全文
posted @ 2017-09-18 15:55 一串字符串 阅读(2149) 评论(0) 推荐(0) 编辑
摘要: 1:数组中存储的数据也可以是string类型的。代码如下: // 6.22.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <string> using namespace std; int main( 阅读全文
posted @ 2017-09-18 09:27 一串字符串 阅读(393) 评论(0) 推荐(0) 编辑
摘要: 1:使用“》”、“!=”、“>=”等比较运算符可以比较两个字符串的内容。比较的方法是将两个string字符串从头开始比较每一个字符,直到出现两者不一致。比较这两个不相同的字符的字面值,得出相应的结果。代码如下: // 6.21.cpp : 定义控制台应用程序的入口点。 // #include "st 阅读全文
posted @ 2017-09-18 08:57 一串字符串 阅读(9861) 评论(0) 推荐(0) 编辑
摘要: 1:使用+可以将两个string 字符串连接起来。同时,string还支持标准输入输出函数。代码如下: // 6.20.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <string> using na 阅读全文
posted @ 2017-09-18 08:43 一串字符串 阅读(1211) 评论(0) 推荐(0) 编辑