1 append(string T&);字符串拼接

2 c_str

string.c_str是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址。

3 empty();判断是否为空

4 erase

删除

5 find

在字符串中查找Find content in string

6 find_first_not_of

Find absence of character in string

7 find_first_of

Find character in string

8 find_last_not_of

Find non-matching character in string from the end

9 find_last_of

Find character in string from the end

10 rfind

Find last occurrence of content in string

11 insert

插入

12 replace

替换

打印字符串,并执行

system(string1[i].c_str());

//std::array<std::string, 数组元素个数>

 #include <iostream>
#include <array>
#include <string>
using namespace std; void main()
{
std::array<std::string, > string1 = { "calc","notpad","tasklist","mspaint","write" };//std::array<std::string, 数组元素个数> for (int i = ; i < ; i++)
{
std::cout << string1[i] << std::endl;//打印
system(string1[i].c_str());//执行
} system("pause");
};

字符串相加,类似C的strcat函数

 #include <iostream>
#include <array>
#include <string>
using namespace std; void main()
{
std::string str1 = "task";
std::string str2 = "list";
std::string str3 = str1 + str2; system(str3.c_str()); system("pause");
}

C: char str[]

C++: string

注意区分两者不同,string是类

error C3863: 不可指定数组类型“char [100]”

 #include <iostream>

 void main()
{
char str[];
str = "hello";//error C3863: 不可指定数组类型“char [100]” std::string str1;
str1 = "world";
}

append可以实现字符串拼接

 #include <iostream>
#include <string> void main()
{
std::string str1("hello");
std::string str2("world");; str1.append(str2);//字符串拼接 std::cout << str1 << std::endl;
}

str1.insert(str1.begin(), 'X');//头部插入

str1.insert(str1.end(), 'X');//尾部插入

str1.insert(str1.begin(), 3, 'X');//头部插入3个X

str1.insert(str1.begin() + 3, 3, 'X');//头部插入3个X,在开头第3个位置插入

 #include <iostream>
#include <string> void main()
{
std::string str1("hello");
std::string str2("world");; str1.insert(str1.begin(), 'X');//头部插入
str1.insert(str1.end(), 'X');//尾部插入 str1.insert(str1.begin(), , 'X');//头部插入3个X str1.insert(str1.begin() + , , 'X');//头部插入3个X,在开头第3个位置插入 std::cout << str1 << std::endl;
}

str.erase(str.begin());//删除第一个字符
str.erase(3, 4);//从下标3开始,删除4个字符(下标从0开始)

 #include <iostream>
#include <string> void main()
{
std::string str("helloworld"); str.erase(str.begin());//删除第一个字符
str.erase(, );//从下标3开始,删除4个字符(下标从0开始) std::cout << str << std::endl;
}

str.replace(0, 3, "china");//从下标0开始,把3个字符替换成china
//位置,长度,字符串

str.replace(0, 3, "china");//从下标0开始,直接插入china

 #include <iostream>
#include <string> void main()
{
std::string str("helloworld"); str.replace(, , "china");//从下标0开始,把3个字符替换成china
//位置,长度,字符串 str.replace(, , "china");//从下标0开始,直接插入china std::cout << str << std::endl;
}

各种find

 #include <iostream>
#include <string> void main()
{
std::string str("helloworld"); std::cout << str.find("wo") << std::endl;//正向查找 std::cout << str.rfind("wo") << std::endl;//反向查找 std::cout << str.find_first_of("wo") << std::endl;//最后一个找到与字符串匹配的字符位置 std::cout << str.find_first_not_of("wo") << std::endl; std::cout << str.find_last_of("wo") << std::endl; std::cout << str.find_last_not_of("wo") << std::endl; std::cout << str << std::endl;
}

string判断是否一样

 #include <iostream>
#include <string> void main()
{
std::string str1("helloworld");
std::string str2("helloworld"); char str3[] = "helloworld";
char str4[] = "helloworld"; std::cout << (str1 == str2) << std::endl;//string重载==
std::cout << (str3 == str4) << std::endl;//判断地址是否一样,地址肯定不一样,永远是0 std::cout << str1.empty() << std::endl;//判断是否为空
}

121456

#include <string>的更多相关文章

  1. 浅谈JSP中include指令与include动作标识的区别

    JSP中主要包含三大指令,分别是page,include,taglib.本篇主要提及include指令. include指令使用格式:<%@ include file="文件的绝对路径 ...

  2. Entity Framework 6 Recipes 2nd Edition(13-9)译 -> 避免Include

    问题 你想不用Include()方法,立即加载一下相关的集合,并想通过EF的CodeFirst方式实现. 解决方案 假设你有一个如Figure 13-14所示的模型: Figure 13-14. A ...

  3. error RC1015: cannot open include file 'afxres.h' 解决办法

    在为WindowsPhone8程序添加本地化的过程中遇到这个问题: 问题原因就是afxres.h文件缺失,下载它,放到VS安装目录下的VS\include目录下就可以了(选择目录的时候注意对应对版本) ...

  4. Mybatis常用总结:参数,返回,执行sql,include等

    1.参数注入1.1用#{0},#{1}的形式,0代表第一个参数,1代表第二个参数 public List<RecordVo> queryList(String workerId, Inte ...

  5. jsp中的@include与jsp:include区别详解

    1 前言 搞java开发的人也许都知道在jsp中引入项目中其他文件有如下两种方式 <%@include file="xxx.jsp"%> <jsp:include ...

  6. JSP中编译指令include与动作指令include的区别

    include指令是编译阶段的指令,即include所包含的文件的内容是编译的时候插入到JSP文件中,JSP引擎在判断JSP页面未被修改, 否则视为已被修改.由于被包含的文件是在编译时才插入的,因此如 ...

  7. C/C++ 中的include

    当需要使用已有的方法或库时, 可以将它们的头文件#include进来. #include会在preprocess过程中被替换成它包含的代码. 头文件中包含了需要使用的函数/变量的声明. 当然声明与定义 ...

  8. 织梦多语言站点,{dede:include filename=''/}引入问题

    织梦模板include插入非模板目录文件出现"无法在这个位置找到"错误的解决办法 以下是dede V55_UTF8 查dede include标签手册 (3) include 引入 ...

  9. PHP 站点相对包含,路径的问题解决方法(include,require)

    以前看了,很多框架,基本上很少使用相对路径包含.而一般很多做php web站点,喜欢用相对路径. 认为这样,无论目录放到那里. 只要跟另外目录关系一致.那么就不会出现问题.如果一个站点,一般都认为,如 ...

  10. 如何让include标签包裹的布局置于屏幕最下方?

    如何让一个Layout 始终在屏幕的下方 我想让<include layout="@layout/bottom" />一直在屏幕下,怎么做? 1.相对布局中用属性  a ...

随机推荐

  1. javascript圆形排列

    显示效果如下: 需要用到的知识: 等于半径长的圆弧所对的圆心角叫做1弧度的角,用符号rad表示,读作弧度.用弧度作单位来度量角的制度叫做弧度制.另外一种度量角的方法是角度制.弧度制的精髓就在于统一了度 ...

  2. Dynamics CRM 2013 初体验(5):Business Rule

    新系统中的Business Rule是个不错的功能,相信它的出现能减少大量的开发工作.在日常开发中,我们需要对记录做大量的业务控制.比如:某字段是否要隐藏,某字段的值是否符合要求以及现实提醒信息等.在 ...

  3. 调用底层的viewController--返回底层

    //返回底层viewController的方法-- - (UIViewController*)GetViewController:(UIView*)uView { for (UIView* next ...

  4. C语言入门(19)——C语言的编码风格

    代码风格好不好就像字写得好不好看一样,如果一个公司招聘秘书,肯定不要字写得难看的,同理,代码风格糟糕的程序员肯定也是不称职的.虽然编译器不会挑剔难看的代码,照样能编译通过,但是和你一个团队进行协作的其 ...

  5. html和js

    1.<input type="button" value="Hello world!"> 2.<button type="butto ...

  6. linux centos 配置 svn 服务器

    首先介绍一下吧,Subversion(SVN) 是一个开源的版本控制系統, 也就是说 Subversion 管理着随时间改变的数据. 这些数据放置在一个中央资料档案库 (repository) 中.  ...

  7. VS2013启动项目调试的时候会启动本地IIS

    VS2013启动项目调试的时候会启动本地IIS ,而在这种状态下去调试程序,会有很多功能用不了,而且还会有错误:如下图: 解决方法,将托管管道模式更改一下就行了:

  8. PHPExcel Fatal error: ZipArchive library is not enabled

    导致上述问题的可能性有两种: 1.没开启php_zip.dll扩展 a.在Windows下的解决办法是: (a1)  在php.ini文件中,将extension=php_zip.dll前面的分号“; ...

  9. H264源码分析(四)

    sub_mb_pred( mb_type ) {       for( mbPartIdx = 0; mbPartIdx < 4; mbPartIdx++ )                  ...

  10. 基于Linux 3.0.8 Samsung FIMC(S5PV210) 的摄像头驱动框架解读(一)

    作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 FIMC这个名字应该是从S5PC1x0開始出现的.在s5pv210里面的定义是摄像头接口.可是它相 ...