From 42317a0988fc2cd534e71a1a11dea55ec4aac140 Mon Sep 17 00:00:00 2001 From: petacreepers23 Date: Mon, 2 Dec 2024 09:44:53 +0100 Subject: [PATCH] convert vec of strings to vec of ints --- include/utilityString.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/utilityString.hpp b/include/utilityString.hpp index 38a0331..9d3ce2b 100644 --- a/include/utilityString.hpp +++ b/include/utilityString.hpp @@ -1,5 +1,6 @@ #include #include +#include /* This file will only have things related with any kind of manipulation to std::string @@ -28,4 +29,19 @@ namespace P23 { return ret; } + /* + Converts a vector of strings which contains numbers to a vector of numbers. + + Ejemplo: vec = {"1", "2", "3", "4"} + from_string_vec_to_int_vec(vec) -> {1, 2, 3, 4} + */ + std::vector from_string_vec_to_int_vec(std::vector vec) { + std::vector ret; + for (const auto& str : vec) { + int num; + std::from_chars(str.data(), str.data() + str.size(), num); + ret.push_back(num); + } + return ret; + } } \ No newline at end of file