Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
auto split the input
// the input is provided in one line, containing commas and integrals. the following code split the input and read them into an array.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string input;
cin >> input;
replace(input.begin(), input.end(), ',', ' ');
stringstream ss;
ss.str(input);
int data[1000];
int count = 0;
string temp;
while (ss >> data[count])
{
count++;
}
// above is the reading and storing section
for (int i = 0; i < count; i++)
{
cout << data[i];
}
// output
return 0;
}
@yangl1996

This comment has been minimized.

Show comment Hide comment
@yangl1996

yangl1996 Oct 17, 2014

没有必要这么复杂。直接用一个char存符号,之后使用cin >> a >> char >> b即可。

Owner

yangl1996 commented Oct 17, 2014

没有必要这么复杂。直接用一个char存符号,之后使用cin >> a >> char >> b即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment