aboutsummaryrefslogtreecommitdiff
path: root/cpp00/ex01/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp00/ex01/utils.cpp')
-rw-r--r--cpp00/ex01/utils.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/cpp00/ex01/utils.cpp b/cpp00/ex01/utils.cpp
new file mode 100644
index 0000000..27c7daa
--- /dev/null
+++ b/cpp00/ex01/utils.cpp
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* utils.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 07:31:30 by charles #+# #+# */
+/* Updated: 2020/04/13 08:43:18 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "utils.hpp"
+
+int getInt()
+{
+ std::string s;
+ int tmp;
+
+ std::cin >> s;
+ for (size_t i = 0; i < s.length(); i++)
+ if (!isdigit(s[i]))
+ return (-1);
+ std::istringstream(s) >> tmp;
+ return tmp;
+}