forked from nisarg0/Algorithm-Implementation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_input.cpp
More file actions
33 lines (22 loc) · 726 Bytes
/
string_input.cpp
File metadata and controls
33 lines (22 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// If the input format of a string is know...
// Ex.str = "233+923i" How to extract numbers
#include<bits/stdc++.h>
using namespace std;
int main(){
string str = "233+923i";
int a,b;
sscanf(str.c_str(), "%d+%di", &a, &b);
cout << a << " " << b << endl;
//********************************* OR ***********************************
str = "I am Nisarg and I love DS-Algo";
vector<string> vec;
istringstream iss(str);
for(string s;iss >> s;)
vec.push_back(s);
for(int i=0;i<vec.size();i++)
cout << vec[i] << endl;
//************************* String with spaces input ********************
// string input;
// cin.ignore();
// getline(cin, input, '\n');
}