Last active
February 4, 2021 21:08
-
-
Save kiprasmel/c35a4663db5e4a56688a3b5fd0e3ce14 to your computer and use it in GitHub Desktop.
stdin parsing with simple streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
// replace this with `cin` or `ifstream` or whatever) | |
stringstream ss("ayyy lmao asd_qwe: 69, 420,1337, nice yo\nhehe xd: 1, 2, 3, kekw pog"); | |
string a, b, c; | |
getline(ss, a, ' '); // ayyy (till space) | |
getline(ss, b, ' '); // lmao (till space) | |
getline(ss, c, ':'); // asd_qwe (till colon) | |
int d, e, f; | |
ss >> d; ss.get(); // 69 (& eat comma) | |
ss >> e; ss.get(); // 420 (& eat comma) | |
ss >> f; ss.get(); // 1337 (& eat comma) | |
cout << "a " << a << "; b " << b << "; c " << c << "\n"; | |
cout << "d " << d << "; e " << e << "; f " << f << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment