-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv.cpp
38 lines (35 loc) · 796 Bytes
/
csv.cpp
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
37
38
#include <string>
#include <stdexcept>
double
stod_strict(const std::string& str)
{
size_t i = 0;
double v = std::stod(str, &i);
for (size_t n = str.length(); i < n; i++) {
if (!std::isspace(str[i]))
throw std::invalid_argument("stod_strict: no conversion");
}
return v;
}
float
stof_strict(const std::string& str)
{
size_t i = 0;
float v = std::stof(str, &i);
for (size_t n = str.length(); i < n; i++) {
if (!std::isspace(str[i]))
throw std::invalid_argument("stof_strict: no conversion");
}
return v;
}
int
stoi_strict(const std::string& str)
{
size_t i = 0;
int v = std::stoi(str, &i);
for (size_t n = str.length(); i < n; i++) {
if (!std::isspace(str[i]))
throw std::invalid_argument("stod_strict: no conversion");
}
return v;
}