stringstream或istringstream的使用

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    // 使用 stringstream
    string sinput;
    while (getline(cin,sinput)){
        stringstream ss;
        ss << sinput;
        long long tmp,ans=0;
        while (ss >> tmp){
            ans += tmp;
        }
       cout << ans << endl;
    }
    return 0;
}







#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    // 使用 istringstream
    string sinput;
    while (getline(cin,sinput)){
        istringstream ss(sinput);
        long long tmp,ans=0;
        while (ss >> tmp){
            ans += tmp;
        }
       cout << ans << endl;
    }
    return 0;
}




全部评论

相关推荐

哈基米南北绿豆114...:大三下民办二本通信工程转码,崩溃的是我,不要问我为什么行情这么差还转码,计算机只是日暮西山,通信工程是漫漫长夜😭查看图片
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务