string

来源:互联网 发布:日系护肤品知乎 编辑:程序博客网 时间:2024/06/09 23:37

39.string可以用+号连接,将字符串连在一起。(原理是重载了加号)

40.字符串比较大小,从第一个字符开始比较,比较字符的ACMLL值,只要比较出来大小就不在比较。

41.Size_type的返回值是相当于unsigned int。

47.string当中常用的函数:

append   函数能将某字符串(或数据串)加到某字符串后面  
  assign   函数能将字符串(或数据串)的内容设定给某字符串  
  at   函数能回传字符串中位于某个位置的字符  
  begin   函数将回传该字符串的起始定位器  
  c_str   函数能将字符串对象中的内容,以c语言字符串的方式输出  
  capacity   函数能回传目前所能控制的对象容器大小  
  compare   函数将会回传   可控制的字符吕容量  
  copy   函数能将数据串的内容复制到加一个数据串中  
  data   函数能将数据串的第一个起始指针传出  
  empty   函数能判断数据串是否为空串  
  end   函数将回传该字符串的终止定位器  
  erase   函数将容器中的数据清除  
  find   函数能在容器中寻找符合求的数据其出现的位置  
  find_first_of   函数能在容器中寻找第一个符合特定要求的数据出现的位置  
  find_first_not_of   函数能在容器中寻找第一个不符合特定要求的数据出现的位置  
  find_last_of   函数能在容器中寻找最后一个符合特定要求的数据出现的位置  
  find_last_not_of   函数能在容器中寻找最后一个不符合特定要求的数据出现的位置  
  insert   函数能将数据插入到容器中的某个特定位置  
  length   函数能计算数据串的长度  
  replace   函数能将数据插入到容器中的某个特定位置  
  reserve   函数能保证capacity函数的回传值,一定大于某数  
  resize   函数能确定size函数的回传值,一定大于某数  
  rfind   函数能在容器中寻找最后一个符合特定要求的数据出现的位置  
  size   函数能回传目前对象容器的大小  
  substr   函数能将串裁减为更少的串  
  swap   函数能将两个串的内容交换  
  max_size   函数能将两个串的内容交换  
   
  getline   函数能通过输入装置,将输入的数据存储到容器中  
  swap函数能将两个数据串中的内容做交换  

字符串函数
str... 字符串操作系统函数     string.h
     strcat 把一个串加到另一串(合并)
     strchr 扫描串中某个给定字符的第一次出现(搜索)
     strcmp 把一个串与另一个串进行比较(比较)
     strcspn 扫描串中不包含给定串集合字符的第一个段(比较)
     strdup 拷贝串到一个新创建的位置(拷贝)
     stricmp 将一个串与另一个串比较, 不管大小写(比较)
     strcmpi 将一个串与另一个串比较, 不管大小写(比较)
     strlen 计算串的长度(搜索)
     strlwr 转换串中的大写字母为小写(修改)
     strncat 把串中的一部分加到另一串(合并)
     strncmp 把串中的一部分与另一串中一部分比较(比较)
     strncpy 拷贝串中的给定字节数到另一串, 必要时截断或填加(拷贝)
     strncmpi 把串中的一部分与另一串中一部分比较, 不管大小写(比较)
     strnset 将串中指定数目字节设置为给定字符(修改)
     strpbrk 扫描给定集合中任一字符在串上第一次出现(搜索)
     strchr 扫描给定字符在串中的最后一次出现(搜索)
     strrev 颠倒串顺序(修改)
     strset 把串中所有字符设置为给定字符(修改)
     strspn 扫描给定字符集合的子集在串中第一次出现的段(搜索)
     strstr 扫描给定子串在串中的出现(搜索)
     strtod 把一串转换为双精度值(转换)
     strtok 搜索串中一单词, 该单词由第二个串中定义的符号分隔(搜索)
     strtol 把一串转换为长整型值(转换)

     strupr 把串中所有小写字母转换成大写(修改)




49.string的代码如下:

   #include "Utility.h"

 

//加载资源

void LoadResources( const char * _path )

{

cout << _path << endl;

}

 

void main()

{

string str1 = "Hello STL_string";

cout << str1 << endl;

//cin >> str1;

//cout << str1 << endl;

 

string path = "res\\texture\\123.jpg";

LoadResources(path.c_str());

 

cout << path.size() << endl;

cout << path.length() << endl;

 

for (unsigned int i = 0; i < path.size(); ++i)

cout << path[i] << endl;

 

// string的 + 的作用

string front = "hello";

string back = " world";

front += back;

cout << front << endl;

 

string str2 = "Abc";

string str3 = "Hello" + ("," + str2);

cout << str3 << endl;

 

//------------append()------------

cout << "------------append()------------" << endl;

string str4;

 

str4.append("A");

cout << str4 << endl;

 

char * pStr = "HelloWorld";

str4.append(pStr, pStr + 5);

cout << str4 << endl;

 

str4.append(5, 'M');

cout << str4 << endl;

 

//------------assign()------------

cout << "------------assign()------------" << endl;

str4.assign("NBA");

cout << str4 << endl;

 

//------------at()------------

cout << "------------at()------------" << endl;

cout << str4.at(1) << endl;

 

//------------back()------------

cout << "------------back()------------" << endl;

cout << str4.back() << endl;

 

//------------copy()------------

cout << "------------copy()------------" << endl;

char cArray1[10] = {};

str4.copy(cArray1, 2);

cout << cArray1 << endl;

 

//------------find()------------

cout << "------------find()------------" << endl;

unsigned int index = str4.find('B');

cout << index << endl;

 

//------------rfind()------------

cout << "------------rfind()------------" << endl;

unsigned int lastIndex = path.rfind('\\');

unsigned int usefulIndex = lastIndex + 1;

for (; usefulIndex < path.size(); ++usefulIndex)

{

cout << path[usefulIndex];

}

cout << endl;

 

//------------substr()------------

cout << "------------substr()------------" << endl;

string temp = "I AM A TEACHER";

string sub1 = temp.substr(7, 7);

cout << "temp:" << temp << endl;

cout << "sub1:" << sub1 << endl;

system("pause");

}


0 0
原创粉丝点击