C++每日一练(Strings)

来源:互联网 发布:成都linux招聘 编辑:程序博客网 时间:2024/05/20 11:26

一、今日课题

string

二、实战演练

string 其实相当于一个保存字符的序列容器,因此除了有字符串的一些常用操作以外,还有包含了所有的序列容器的操作。字符串的常用操作包括:增加、删除、修改、查找比较、链接、输入、输出等。

1)有何用?

有了string 后,C++的字符文本处理功能总算得到了一定补充,加上配合STL其他容器使用,其在文本处理上的功能已经与perl, shell, php的距离缩小很多了。

2)怎么用?

  • 充分使用string操作符
#include <iostream>#include<string>using namespace std;int main(){    string strinfo = "Please Input your name:";    cout << strinfo;    cin >> strinfo;    if (strinfo == "winter")        cout << "you are winter" << endl;    else if (strinfo != "wendy")        cout << "you are not wendy" << endl;    strinfo += ", welcome to China!";    cout << strinfo << endl;    cout << "Your name is:" << endl;    string strtmp = "How are you?" + strinfo;    for (int i = 0; i < strtmp.size(); ++i)    {        cout << strtmp[i];    }    system("pause");    return 0;}
  • 眼花缭乱的string find 函数

这里写图片描述

3)Access & Operations

这里写图片描述


三、C++树

这里写图片描述


10/9/2016 3:42:26 PM

0 0