Skip to content

Instantly share code, notes, and snippets.

@yangl1996
Created September 28, 2014 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangl1996/1f85361ec17002cd9f4f to your computer and use it in GitHub Desktop.
Save yangl1996/1f85361ec17002cd9f4f to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

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