c++拆分字符串方法:

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>

int main() {
using namespace std;
string sentence = "Something in the way she moves...";
istringstream iss(sentence);
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
ostream_iterator<string>(cout, "\n"));
}

你也可以将分割后的字符串复制到vector内:

vector<string> tokens;
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
back_inserter<vector<string> >(tokens));

原文地址:http://www.jobui.com/mianshiti/it/cpp/8186/

C++ 拆分字符串-copy()的更多相关文章

  1. 拆分字符串,GetHtmlByWebBrowser,UnicodeToMBCS,提升进程权限

    1. // 根据字符串,拆分字符串,相当于vb中的split函数 function SplitString(const Source, ch: string): TStringList; var te ...

  2. swift和OC - 拆分数组 和 拆分字符串

    1. 拆分数组 /// 根据 数组 截取 指定个数返回 多个数组的集合 func splitArray( array: [Date], withSubSize subSize: Int) -> ...

  3. R语言拆分字符串

    R语言拆分字符串 aaa<-"aa;bb;cc"ccc<-strsplit(aaa,split=";") bbb<- unlist(strsp ...

  4. 【SQL】sql版Split函数。用于拆分字符串为单列表格

    功能与.net版string.Split函数类似,只不过.net返回的是数组,这个返回的是一个单列表格,每个拆分出来的子串占一行.可选是否移除空格子串和重复项.市面上类似的函数不算少,但大多都是在循环 ...

  5. oracle11g 拆分字符串的详细技巧

    转自:http://m.blog.csdn.net/article/details?id=51946573 <-->功能需求                 有一个比较长的SQL语句,查询 ...

  6. python split()函数使用拆分字符串 将字符串转化为列表

    函数:split()Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list ...

  7. PHP基础语法: echo,var_dump, 常用函数:随机数:拆分字符串:explode()、rand()、日期时间:time()、字符串转化为时间戳:strtotime()可变参数的函数:PHP里数组长度表示方法:count($attr[指数组]);字符串长度:strlen($a)

    PHP语言原理:先把代码显示在源代码中,再通过浏览器解析在网页上 a. 1.substr;  //用于输出字符串中,需要的某一部分 <?PHP $a="learn php"; ...

  8. Java 数据类型之间的转换 拆分字符串 Date/Calendar的转换

    数据类型转换 1. String - Int String str="123"; int i=1; int str=Integer.parseInt(str); String i= ...

  9. 字符串copy

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...

随机推荐

  1. 【LeetCode OJ】Pascal's Triangle

    Prolbem Link: http://oj.leetcode.com/problems/pascals-triangle/ Just a nest-for-loop... class Soluti ...

  2. 升级IOS 9 和 XCode 7 引起的问题

    问题一: 升级xcode 7最低的系统配置要求 升级了ios9 后使用 xcode 6.1 已经不能用了,必须升级 xcode 7才行,原先的系统是OSX 10.10.1 版本.而xcode 7.0 ...

  3. HDU 1053 & HDU 2527 哈夫曼编码

    http://acm.hdu.edu.cn/showproblem.php?pid=1053 #include <iostream> #include <cstdio> #in ...

  4. HDU 4460

    http://acm.hdu.edu.cn/showproblem.php?pid=4460 水题一道,oj时间卡的非常奇怪,把spfa的queue开成全局卡线过,别的全挂了,迪杰斯特拉的手写堆都超时 ...

  5. Java学习第二天

    一.两个常用工具 1.随机生产一个[0,1)之间的数 Math.random() 举例: double box =Math.random(); //产生随机小数 [0,1) System.out.pr ...

  6. C++学习笔记12:运算符重载(赋值操作符1)

    为数偶类定义专用的赋值操作符 class Couple { public: Couple(, ) :_a(a), _b(b) {} Couple(const Couple &c):_a(c._ ...

  7. 机器学习技法-AdaBoost元算法

    课程地址:https://class.coursera.org/ntumltwo-002/lecture 重要!重要!重要~ 一.Adaptive Boosting 的动机 通过组合多个弱分类器(hy ...

  8. Open vSwitch FAQ (一)

    Basic Configuration Q: How do I configure a port as an access port? A: Add "tag=VLAN" to y ...

  9. 解决MySQL中【Cannot load from mysql.proc. The table is probably corrupted

    [错误过程]:MySQL从5.1升级至5.5后在调用存储过程时报出“Cannot load from mysql.proc. The table is probably corrupted.” [造成 ...

  10. 1-1 Windows应用程序的特点

    主要内容:介绍Windows应用程序的特点,并附加了消息和事件的一些区别 //以后该分类中字体均采用 隶书 4(14pt) 1. 面向对象 <1>针对Windows应用本身,如记事本界面, ...