istringstream 类用于执行C++风格的串流的输入操作

istringstream用空格作为字符串分隔符

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void test()
{
    {
        //istringstream iss;
        //iss.str("#123 1.23 aaa ,zzz kk,k oo.jjj");
        istringstream iss("#123 1.23 aaa ,zzz kk,k oo.jjj");
        
        cout << iss.str() << endl;

        char ch;
        iss >> ch;
        cout << ch << endl;

        int i;
        iss >> i;
        cout << i << endl;

        float f;
        iss >> f;
        cout << f << endl;

        char buf[1024];
        iss >> buf;
        cout << buf << endl;

        iss.ignore(100, ',');//ignore 忽略前100个字符或者忽略第一个逗号前面的内容包含第一个逗号,然后显示删除内容之后到第一个空格之间的字符。
        iss >> buf;
        cout << buf << endl;
    }
}

int main(int argc, char* argv[])
{   
    test();
    return 0;
}

结果:

istringstream 用法的更多相关文章

  1. c++ istringstream用法

    istringstream用法,见如下代码 #include <iostream> #include"sstream" using namespace std; int ...

  2. sstream

    sstream用法 #include<iostream> #include<sstream> #include<string> using namespace st ...

  3. istringstream()函数的用法

    istringstream()函数的用法 头文件:#include 功能:将一个含有多个空格的字符串分割开来 eg:

  4. c++ istringstream的用法

    一.测试代码 istringstream 是将字符串变成字符串迭代器一样,将字符串流在依次拿出,比较好的是,它不会将空格作为流.这样就实现了字符串的空格切割. #include<iostream ...

  5. C++中的 istringstream 的用法

    C++引入了ostringstream.istringstream.stringstream这三个类,要使用他们创建对象就必须包含<sstream>这个头文件. istringstream ...

  6. 标准C++中的string类的用法总结

    标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...

  7. VC++ 标准C++中的string类的用法总结

    相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...

  8. [C++][语言语法]标准C++中的string类的用法总结

    转自:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 要想使用标准C++中string类,必须要包含 #include ...

  9. c++ list, vector, map, set 区别与用法比较

    http://blog.csdn.net/alex_xhl/article/details/37692297 List封装了链表,Vector封装了数组, list和vector得最主要的区别在于ve ...

随机推荐

  1. zTree 树形控件 ajax动态加载数据

    很久没搞过树形控件了 , 再次接触看官网文档有点没懂,于是在网上找了个代码copy上,但数据是写死的,就想这在用ajax异步取出数据替换,下面是js代码 <SCRIPT type="t ...

  2. Commit message 的写法规范。本文介绍Angular 规范(

    Commit message 的写法规范.本文介绍Angular 规范( http://www.ruanyifeng.com/blog/2016/01/commit_message_change_lo ...

  3. attributes["wv"].nodeValue

    w 获取自定义属性的值 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  4. Akka Essentials - 1

    参考Akka Essentials   1 Introduction to Akka Actor Model Actor模式的由来 In 1973, Carl Hewitt, Peter Bishop ...

  5. 报错:Cannot remove entries from nonexistent file c:\program files\anaconda3\lib\site-packages\easy-install.pth

    Outline 这两天通过“掘金量化终端”跑模型策略,之前装好环境一直ok,可以顺畅的Running~ 下午重装了下 Anaconda,刚才跑的时候提示 缺少“gm”模块 (掘金量化必须包): 就按照 ...

  6. Android---55---Web Service概述

    Web Service 是什么? /*w3school*/ Web Services 是应用程序组件 Web Services 使用开放协议进行通信 Web Services 是独立的(self-co ...

  7. Redis二(Hash操作)

    Hash操作 Hash操作,redis中Hash在内存中的存储格式如下图: hset(name, key, value) 1 2 3 4 5 6 7 8 9 # name对应的hash中设置一个键值对 ...

  8. mysql-xtrabackup

    使用xtrabackup进行MySQL数据库备份 2013年10月04日 ⁄ MySQL ⁄ 共 11306字 ⁄ 使用xtrabackup进行MySQL数据库备份已关闭评论 ⁄ 被围观 34,116 ...

  9. Differences between Python2 and Python3

    @1:str, repr和反引号是Python将值转为字符串的3种方法repr创建一个字符串,它以合法的Python表达式的形式表示该字符串.Python2还有反引号`,但Python3中没有反引号, ...

  10. PAT 天梯赛 L1-010. 比较大小 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-010 AC代码 #include <iostream> #include <cstdio&g ...