为什么我的程序没有输出:
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)
基本上我试图解析逗号分隔的字符串,任何更平滑的方式来做这将帮助我巨大.