-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrtol.cpp
87 lines (73 loc) · 1.53 KB
/
Strtol.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* \file Strtol.cpp
* \brief Convert string values to long int
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
// Strings
{
std::cout << "Strings:" << std::endl;
const std::vector<std::string> values
{
// Strings
"true",
"TRUE",
"false",
"FALSE",
"xxxxxx",
"NULL",
"nullptr",
""
};
for (const auto &it_value : values) {
const long int liRv = std::strtol(it_value.c_str(), nullptr, 10);
std::cout << STD_TRACE_VAR(it_value) << " -> " << liRv << std::endl;
}
std::cout << std::endl;
}
// Digits
{
std::cout << "Digits:" << std::endl;
const std::vector<std::string> values
{
"1",
"2",
"+1",
"+2",
"-1",
"-2",
"0",
"-0"
};
for (const auto &it_value : values) {
const long int liRv = std::strtol(it_value.c_str(), nullptr, 10);
std::cout << STD_TRACE_VAR(it_value) << " -> " << liRv << std::endl;
}
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
Strings:
it_value: true -> 0
it_value: TRUE -> 0
it_value: false -> 0
it_value: FALSE -> 0
it_value: xxxxxx -> 0
it_value: NULL -> 0
it_value: nullptr -> 0
it_value: -> 0
Digits:
it_value: 1 -> 1
it_value: 2 -> 2
it_value: +1 -> 1
it_value: +2 -> 2
it_value: -1 -> -1
it_value: -2 -> -2
it_value: 0 -> 0
it_value: -0 -> 0
#endif