Skip to content

Commit a7caf1f

Browse files
committed
Functions Convertions.
1 parent 3f7a368 commit a7caf1f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Utils/Converts.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "Converts.h"
2+
3+
int stringToInt(std::string value, std::string_view message) {
4+
try {
5+
int v = std::stoi(value);
6+
return v;
7+
}
8+
catch (std::invalid_argument const& ex) {
9+
std::cout << message << "Erreur final : " << ex.what() << std::endl;
10+
}
11+
return 0;
12+
}
13+
14+
double stringToDouble(std::string value, std::string_view message) {
15+
try {
16+
double v = std::stod(value);
17+
return v;
18+
}
19+
catch (std::invalid_argument const& ex) {
20+
std::cout << message << "Erreur final : " << ex.what() << std::endl;
21+
}
22+
return 0;
23+
}

src/Utils/Converts.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
#include <string_view>
5+
#include <sstream>
6+
#include <stdexcept>
7+
#include <algorithm>
8+
#include <optional>
9+
#include <map>
10+
#include <functional>
11+
#include <fstream>
12+
13+
int stringToInt(std::string value, std::string_view message);
14+
15+
double stringToDouble(std::string value, std::string_view message);

0 commit comments

Comments
 (0)