首页 > 编程语言 > 详细

c++ istringstream用法

时间:2019-12-05 16:27:36      阅读:96      评论:0      收藏:0      [点我收藏+]

istringstream用法,见如下代码

#include <iostream>
#include"sstream"
using namespace std;
int main() {
    istringstream is("I am\tlove C++\nand I love C");
    string str;
    //默认是空格或者回车符或者tab,会输出如下内容:I am love C++ and I love C
    while (is>>str){
        cout<<str<<" ";
    }
    cout<<endl;
    istringstream istringstream1("30+2*2+3-");
    long ans;
    char op;
    istringstream1>>ans;
    //会得到如下内容 30 + 2 * 2 + 3 -
    while (istringstream1 >> op) {
        cout<<ans<<" "<<op<<" ";
        istringstream1>>ans;
    }
    cout<<endl;

    istringstream istringstream2("20q230r4");
    istringstream2>>ans;
    //会得到如下内容  20 q 230 r
    while (istringstream2>>op){
        cout<<ans<<" "<<op<<" ";
        istringstream2>>ans;
    }
    return 0;
}

 

 

c++ istringstream用法

原文:https://www.cnblogs.com/AntonioSu/p/11989438.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!