小编Sun*_*dal的帖子

如何使用istringstream提取混合格式

为什么我的程序没有输出:

10
1.546
,Apple 1
Run Code Online (Sandbox Code Playgroud)

代替

10
1
<empty space>
Run Code Online (Sandbox Code Playgroud)

这是我的计划:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main () {
    string str = "10,1.546,Apple 1";
    istringstream stream (str);
    int a;
    double b;
    string c, dummy;
    stream >> a >> dummy >> b >> dummy >> c;
    cout << a << endl;
    cout << b << endl;
    cout << c << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

基本上我试图解析逗号分隔的字符串,任何更平滑的方式来做这将帮助我巨大.

c++ formatted-input istringstream

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

c++ ×1

formatted-input ×1

istringstream ×1