d06 ex00 fini

This commit is contained in:
hugogogo
2022-03-08 16:51:12 +01:00
parent 4ee3ae3e7d
commit 315f62eb96
8 changed files with 158 additions and 90 deletions

View File

@@ -1,8 +1,23 @@
#include "convert.h"
//Char toInt(str) {
//
//}
void fromInt(int value) {
// char
std::cout << std::setw(7) << std::left << "char";
if (value < 0 || value > std::numeric_limits<char>::max())
std::cout << B_RED << "impossible" << RESET "\n";
else if (!isprint(value))
std::cout << B_RED << "non displayable" << RESET "\n";
else
std::cout << B_CYAN << static_cast<char>(value) << RESET "\n";
// float
std::cout << std::setw(7) << std::left << "float" << B_CYAN
<< static_cast<float>(value) << RESET "\n";
// double
std::cout << std::setw(7) << std::left << "double" << B_CYAN
<< static_cast<double>(value) << RESET "\n";
}
bool isInt(std::string str) {
std::string int_xtrem = MAX_INT;
@@ -24,17 +39,14 @@ bool isInt(std::string str) {
}
bool checkInt(std::string str) {
// int i;
std::cout << "int\n";
int i;
if (!isInt(str))
return false;
// i = toInt(str);
// std::cout << "int"RESET" equal to : "B_CYAN << i << RESET << "\n";
// fromInt(i);
std::istringstream(str) >> i;
std::cout << B_CYAN << i << B_YELLOW " int" RESET "\n";
fromInt(i);
return true;
}