I have the following program that prints green text to the terminal:
#include <iostream>
#include <string>
std::string colorize_forground(std::string const& message, int const& background) {
return std::string("\e[38;5;" + std::to_string(background) + "m" + message + "\x1b[0m");
}
int main() {
std::cout << colorize_forground("hello world in green", 106) << '\n';
}
However, when I compile the program with the following warning flag,
g ++ -std = C ++ 1y -pedantic -o main prob.cpp
I get this warning:
main.cpp: In function βstd::string colorize_forground(const string&, const int&)β:
main.cpp:6:21: warning: non-ISO-standard escape sequence, '\e' [enabled by default]
return std::string("\e[38;5;" + std::to_string(background) + "m" + message + "\x1b[0m");
How to continue using -pedantic but ignore the warning for this particular function?
I am trying to use gcc Diagnostic Pragmas to ignore this escape sequence warning. I wrapped the function as follows, but it still raises a warning.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-pedantic"
std::string colorize_forground(std::string const& message, int const& background) {
return std::string("\e[38;5;" + std::to_string(background) + "m" + message + "\x1b[0m");
}
#pragma GCC diagnostic pop