-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_generic.cpp
More file actions
36 lines (32 loc) · 765 Bytes
/
get_generic.cpp
File metadata and controls
36 lines (32 loc) · 765 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
34
35
36
#include <print>
#include <string>
#include <sstream>
#include <istream>
#include <iostream>
template<typename T>
T get(std::istream& is = std::cin) {
T input;
is >> input;
return input;
}
template<typename... Ts>
std::istream& get(std::istream& is, Ts&... inputs) {
((is >> inputs), ...);
return is;
}
template<typename... Ts>
auto getline(std::istream& is, Ts&... inputs) {
using std::getline;
std::string inputline;
getline(is, inputline);
std::istringstream iss{ inputline };
((iss >> inputs), ...);
return iss.rdstate();
}
int main() {
std::println("Enter number op number (eg. 1.2 + 3.4):");
double a, b;
char op;
auto st = getline(std::cin, a, op, b);
std::println("{} {} {}", a, op, b);
}