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

比如在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. linux&nbsp;ip地址自动获取,ip地址…

    linux ip地址自动获取,ip地址手动设置(图文解释) 2011-04-19 16:19:31| 分类: 服务器(appache/n | 标签: |字号大中小 订阅 linux ip地址自动获取( ...

  2. CodeForces 467D(267Div2-D)Fedor and Essay (排序+dfs)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 快速部署Kubernetes集群管理

    这篇文章介绍了如何快速部署一套Kubernetes集群,下面就快速开始吧! 准备工作 //关闭防火墙 systemctl stop firewalld.service systemctl disabl ...

  4. 星级评分--封装成jquery插件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. Spring Security 表达式(Expressions) - hasRole示例

    1.概述 Spring Security使用强大的Spring Expression Language(SpEL)提供各种各样的表达式.大多数这些Security表达式是针对上下文对象(当前经过身份验 ...

  6. Linux之常用命令简析

    ls cd mkdir rmdir touch ln cp rm mv 1.ls   显示当前目录下的文件及文件夹(不显示隐藏的) -l   显示详细信息 --all  显示隐藏的文件及文件夹(就是显 ...

  7. 【转】PHP实现下载与压缩文件的封装与整理

    [转]PHP实现下载与压缩文件的封装与整理    https://mp.weixin.qq.com/s/BUI3QsdNi6Nqu0NhrUL8hQ 一.PHP实现打包zip并下载功能 $file_t ...

  8. solidity 学习笔记(6)call 函数

    call() 方法 call()是一个底层的接口,用来向一个合约发送消息,也就是说如果你想实现自己的消息传递,可以使用这个函数.函数支持传入任意类型的任意参数,并将参数打包成32字节,相互拼接后向合约 ...

  9. Node.js 内置模块crypto加密模块(3) HMAC

    HMAC:哈希消息认证码 ( Hash-based Message Authentication Code ) HMAC是密钥相关的哈希算法 使用 HMAC 进行加密的Node实现的一种方法: &qu ...

  10. openinstall的免费服务对App推广有哪些帮助?

    想在微信中下载 App,需要“点击右上角打开浏览器”,太麻烦: 想深入查看微信分享内容,需要手动打开 App 搜索,不方便: 想给 App 做推广,Android 需要多个渠道人工打包,效率低: .. ...