• istringstream 用法


    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;
    }

    结果:

  • 相关阅读:
    缅怀
    74LS164的使用
    跑步
    Datasheet,你会读么?[转]
    清华附小给的书单
    iOS-小知识
    网络-GET&POST
    网络-基础
    网络-HTTP其他常见方法
    数据解析
  • 原文地址:https://www.cnblogs.com/dfyz/p/6759427.html
Copyright © 2020-2023  润新知