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

比如在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. ACM之Java技巧

    一.Java之ACM注意点 关于四舍五入 小数保留几位:  DecimalFormat df = new DecimalFormat("0.00"); String num = d ...

  2. Word直接发表博客测试

    这是我现在使用的VSCode! 这是另一段测试内容!

  3. Advanced R之数据结构

    看了几本R语言语法相关的书籍,感觉都不怎么好,在实际使用过程中仍然遇到很多难以理解的问题,后来看了Hadley Wickham的Advanced R,好多问题迎刃而解,今天重温了该书的第一章即数据结构 ...

  4. 浏览器原生 form 表单POST 数据的两种方式

    我们在提交表单的时候,form表单参数中会有一个enctype的参数.enctype指定了HTTP请求的Content-Type. 常用有两种:application/x-www-form-urlen ...

  5. 了解protected 以及公用、私有和受保护的继承

    protected成员 可以认为protected访问标号是private 和public 的混合: 1.像private成员一样,protected成员不能被类的用户访问. 2.像public成员一 ...

  6. VMware S/4 HANA OP 1511虚拟机下载,64G内存限制解决方案

    http://www.itpub.net/thread-2057212-1-1.html S4 HANA OP 1511 Scale Out

  7. ACM-ICPC2018北京网络赛 80 Days(双端队列+尺取)

    题目4 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules Ve ...

  8. Javascript实现打开或退出浏览器全屏

    废话不多说,直接上代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www. ...

  9. Android权限之三共享UID和签名

    http://blog.csdn.net/a345017062/article/details/6236263 共享UID 安装在设备中的每一个Android包文件(.apk)都会被分配到一个属于自己 ...

  10. JS 识别生日、性别、年龄

    <script> function IdCard(UUserCard,num){ if(num==1){ //获取出生日期 birth=UUserCard.substring(6, 10) ...