hi recently I was learning C++ in Visual studio when I stopped on a problem when I want to use my method to log an int i need to convert it to const char* but when I do it things just crash is my code:
#include <iostream>
#include <math.h>
#include <Windows.h>
using namespace std;
double pi = 3.14159265358979323846;
class Log {
int level = 1;
public:
void set_Level(const char* lvl)
{
if (lvl == "LOW")
{
level = 1;
}
else if (lvl == "NORMAL")
{
level = 2;
}
else if (lvl == "HIGH")
{
level = 3;
}
else
{
level = 1;
}
}
void Error(const char* message)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x04);
cout << "[ERROR]: " << message << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
}
void Warning(const char* message)
{
if (level != 3)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x06);
cout << "[WARNING]: " << message << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
}
}
void Info (const char* message)
{
if (level == 1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x03);
cout << "[INFO]: " << message << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
}
}
};
int main()
{
Log log;
log.set_Level("LOW");
int x = 10;
log.Info( (const char*) x);
}
it errors out and a page pops up saying:
and its not my class because if i run log.Info("hi");
it works just fine!