在某些情况下需要对输入的字符串进行处理,提取其中的需要的信息.

比如在linux中输入”mkdir test”,新建test文件夹,就需要提取其中的test字符.

提取的方法需要boost库中的函数,提取代码如下:

#include <string>
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){
vector<string> itemlist;
vector<string> contentlist;
string strinfo="name#wangkaixuan$id#111$password#222";
boost::split(itemlist, strinfo, boost::is_any_of("$"));
for (int i = 0; i < itemlist.size(); ++i)
{
cout<<"strlist_"<<i<<"="<<itemlist[i]<<endl;
temp= itemlist[i];
boost::split(contentlist, temp, boost::is_any_of("#"));
cout<<"contentlist_0"<<"="<<contentlist[0]<<endl;
cout<<"contentlist_1"<<"="<<contentlist[1]<<endl; }
return 0;
}
运行结果:iuc@iuc-linux ~/Project/CodeLibrares $ g++ string_find.cpp -o string_find
iuc@iuc-linux ~/Project/CodeLibrares $ ./string_find
strlist_0=name#wangkaixuan
contentlist_0=name
contentlist_1=wangkaixuan
strlist_1=id#111
contentlist_0=id
contentlist_1=111
strlist_2=password#222
contentlist_0=password
contentlist_1=222
iuc@iuc-linux ~/Project/CodeLibrares $

C++ string 类型提取字符串的更多相关文章

  1. delphi中如何将string类型的字符串数据转化成byte[]字节数组类型的数据

    var  S:String;  P:PChar;  B:array of Byte;begin  S:='Hello';  SetLength(B,Length(S)+1);  P:=PChar(S) ...

  2. 将String类型的字符串拼接成以逗号分隔的字符输出

    package test; import java.util.ArrayList; import java.util.List; public class Tesdssss { private sta ...

  3. String类型 堆/字符串池的理解

    1 package test; 2 3 public class StringTest { 4 5 public static void main(String[] args) { 6 7 /** 8 ...

  4. C++的string类型和继承C语言风格的字符串的区别与注意事项

    1.尽可能地在C++程序中使用string,不要使用继承而来的C语言风格的字符串,会出现许多安全问题. 2.C语言的字符串风格,是以空字符结束的,在C++的头文件cstring中定义了C语言风格的字符 ...

  5. C++标准库string类型

    string类型支持长度可变的字符串,C++标准库将负责管理与存储字符相关的内存,以及提供各种有用的操作.标准库string类型的目的就是满足对字符串的一般应用. 本文地址:http://www.cn ...

  6. 5.6.3 String类型

    String类型是字符串的对象包装类型,可以像下面这样使用String构造函数来创建. var stringObject = new String("hello world"); ...

  7. C++标准库string类型的使用和操作总结

    string是C++标准库最重要的类型之一,string支持长度可变的字符串,其包含在string头文件中.本文摘自<C++PRIMER 第四版·特别版>和个人的一些总结. 一.声明和初始 ...

  8. 获取的是 string 类型的字段,直接输出 数字 或者 需要的第几行

    Freight = driver.find_element_by_xpath("//tbody/tr/td[6]").text print(type(Freight)) # 这里输 ...

  9. c++ string类型的定义及方法

    1.c++ 有两种风格的字符串形式  c风格字符串  定义及初始化  char a[]={'h','e','l','l','o','\0'}  或者  char a[]="hello&quo ...

随机推荐

  1. 虚拟机ubuntu和windows共享文件

    设置虚拟机ubuntu和windows共享文件(方便复制文件到本机) (需要安装samba)   登陆ubuntu系统后,点击左边的文件夹.右击新建个文件夹.   设置为共享   ubuntu会提示你 ...

  2. Struts2+JQuery+Json登陆实例

    Struts2+JQuery+Json登陆实例 博客分类: Struts2   在搭建之前.. 首先,需要准备struts2.0框架的5个核心包, 以及jsonplugin-0.32.jar 以及js ...

  3. python中出现 IndentationError:unindent does not match any outer indentation level

    python中出现IndentationError:unindent does not match any outer indentation level 今天在网上copy的一段代码,代码很简单,每 ...

  4. SharePoint 2010 搜索结果没有显示部分文件

    Why SharePoint 2010 search does not show some results?   SharePoint 2010 search is better than ever ...

  5. echarts学习的一些笔记

    工具栏组件 Show 是否显示 Feature 具体显示的功能 saveAslmage  保存图片 Restore 还原 dataZoom  缩放视图 magicType 动态类型切换 toltip组 ...

  6. E20190418-hm

    distinct adj. 明显的,清楚的; 卓越的,不寻常的; 有区别的; 确切的; predicate  vt. 断言,断定; 宣布,宣讲; 使基于; n. 谓语; 述语;

  7. Jsoncpp写“鱘”的json数据,报错。

    最近在用Json::FastWriter生成json数据时,发现一个问题.含有“鱘”字的json字段会多出一个斜杠,不知道是不是编码的问题. C++要使用JSON来解析数据,一般采用jsoncpp. ...

  8. 渲染路径-Unity5 的新旧推迟渲染Deferred Lighting Rendering Path

    Unity5 的新旧延迟渲染Deferred Lighting Rendering Path unity5 的render path ,比4的区别就是使用的新的deferred rendering,之 ...

  9. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:7. 服务调用

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  10. spring框架_IOC与注解

    1.什么是IOC? IoC(Inverse Of Control:反转控制) 2.IOC的作用是什么? 削减计算机程序的耦合(解除我们代码中的依赖关系). 3.关于程序的耦合 /** * 程序的耦合 ...