「✨」 feat: should have finished ex00
This commit is contained in:
@ -6,23 +6,54 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/08 14:30:07 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/08 14:30:36 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/09 10:32:48 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
template <typename T> void _printFloat(T nb) {
|
||||
std::cout << "float: " << static_cast<float>(nb) << "f" << std::endl;
|
||||
}
|
||||
template <typename T> void _printInt(T nb) {
|
||||
std::cout << "int: " << static_cast<int>(nb) << std::endl;
|
||||
std::cout << "int: ";
|
||||
|
||||
if (nb < std::numeric_limits<int>::min() ||
|
||||
nb > std::numeric_limits<int>::max())
|
||||
std::cout << "impossible" << std::endl;
|
||||
else
|
||||
std::cout << static_cast<int>(nb) << std::endl;
|
||||
}
|
||||
template <typename T> void _printChar(T nb) {
|
||||
std::cout << "char: '" << static_cast<char>(nb) << "'" << std::endl;
|
||||
std::cout << "char: ";
|
||||
if (nb < std::numeric_limits<char>::min() ||
|
||||
nb > std::numeric_limits<char>::max())
|
||||
std::cout << "impossible" << std::endl;
|
||||
else if (!isprint(nb))
|
||||
std::cout << "Non displayable" << std::endl;
|
||||
else
|
||||
std::cout << "'" << static_cast<char>(nb) << "'" << std::endl;
|
||||
}
|
||||
template <typename T> void _printDouble(T nb) {
|
||||
std::cout << "double: " << static_cast<double>(nb) << std::endl;
|
||||
}
|
||||
template <typename T> T _ConvertTo(const std::string &str) {
|
||||
std::stringstream ss(str);
|
||||
T ret;
|
||||
|
||||
ss >> ret;
|
||||
return ret;
|
||||
}
|
||||
template <typename T> void _Convert(const std::string &str) {
|
||||
T nb = _ConvertTo<T>(str);
|
||||
|
||||
_printChar(nb);
|
||||
_printInt(nb);
|
||||
_printFloat(nb);
|
||||
_printDouble(nb);
|
||||
}
|
||||
|
Reference in New Issue
Block a user