第2章面对象方法学导论.pptVIP

  • 0
  • 0
  • 约8.95千字
  • 约 64页
  • 2018-12-22 发布于福建
  • 举报
第2章面对象方法学导论

熟悉并使用类 C++标准库提供了string类, string类的属性是一个字符串str,同名函数string是用来初始化符串,另外3个成员函数用来对属性str进行操作。 当定义了一个对象后,这 个对象可以通过这些成员函数展现自身的特性。 使用string类的例子 #include iostream #include string using namespace std; void main( ) { string str1(We are here!); string str2; coutstr1[0]str1[11],str1endl; coutplease input a word:; cinstr2;//输入 一个单词给对象str2 coutlength of str2 isstr2.size()endl; string newstr=str2.substr(3,1);//从 str2的第3位开始截取1个字符 coutnewstr=newstrendl; int i=str1.find(“are”,0);//从字符串str1的位置0开始检索are couti=iendl; } 2.4.1 类图的基本符号 类命名时应遵守以下几条准则: ⑴使用标准术语。 ⑵使用具有确切含义的名词。 ⑶必要时用名词短语作名字。 总之,名字应该是富于描述

文档评论(0)

1亿VIP精品文档

相关文档