./utilscpp
My C++ Utility Library
Colors C++ colors
Library to print your strings with a single function (object)
-
- Add the library and vector to your header
#include <vector>
#include "libcolors.h"
-
- Instantiate the class
Colors c;
-
- Then just call the member function, example:
You must pass 3 arguments to the function, in the following order/prototype:
c.colors( COLOR , CONTENT , INTEGER[ 0 or 1 ] )
std::cout << c.colors( "red" , "My cool string" , 1 ) << '\n';
// ^^^^ ^^^^^^^^^^^^^^^ ^^^
// Color Content Bold
Use 1
if you want bold output and 0
for normal output, complete example:
#include <iostream>
#include <vector>
#include "libcolors.h"
int main(){
Colors c;
std::cout << c.colors( "red" , "My cool string" , 1 ) << '\n';
return 0;
}
If you wanted to see an application working, compile the example:
- First option, compiling with CMake:
mkdir build && cd build
cmake ..
make
Then just run: ./colors "My phrase" --bold --cyan
- Second option, compiling with GNU Make:
make
Then just run: ./colors "My phrase" --bold --purple
Use the -h
or --help
option to see available colors and other information. Exemplo:
./colors --help
Help C++ help
Easily add help to your program
-
- Include library header
#include "help.hh"
If it is on a different path, indicate the full path, for example:
#include "path/to/help.hh"
-
- Pass the command line arguments:
int argc
andchar** argv
to themain()
function, for example:
- Pass the command line arguments:
-
- Instantiate the
Help
class and call thehelp.m_help (argc, argv)
andm_dhelp()
methods/members, for example:
- Instantiate the
Help help;
help.m_help(argc, argv);
help.m_dhelp();
Remove
help.m_dhelp()
if you wish.
Edit/modify the usage()
and m_dhelp()
member functions as usability for your program.
Basic example of use vim main.cpp
:
#include "help.hh"
int main(int argc, char** argv){
Help help;
help.m_help(argc, argv);
help.m_dhelp();
std::cout << "Start my program ..." << '\n';
return 0;
}
To compile this test, run:
make install clean
./help
./help --help
Decimal to binary dec2bin
Convert decimal to binary
mkdir build && cd build
cmake ..
make
./dec2bin 81
1010001
Binary to decimal bin2dec
Convert binary to decimal
mkdir build && cd build
cmake ..
make
./bin2dec 111010
# 58
Alternatively use GNU Make
./bin2dec 10110
# 22
Decimal to hexdecimal dec2hex
Convert decimal to hexadecimal
mkdir build && cd build
cmake ..
make
./dec2hex 8041979
# 7AB5FB
./dec2hex 13021952
# C6B300
Hexadecimal to decimal hex2dec
Convert hexadecimal to decimal
make
./hex2dec A82EB9
# 11022009
./hex2dec 10542C5
# 17121989
Convert ASCII to Decimal ascii2dec
Convert ASCII to decimal
mkdir build && cd build
cmake ..
make
Use quotes!
./ascii2dec "Welcome to C ++ Utils"
# 87 101 108 99 111 109 101 32 116 111 32 67 32 43 43 32 85 116 105 108 115
Convert Decimal to ASCII dec2ascii
Convert Decimal to ASCII
mkdir build && cd build
cmake ..
make
To know the order of numbers use the ascii2dec tool first
Do not use quotes!
./dec2ascii 87 101 108 99 111 109 101 32 116 111 32 67 32 43 43 32 85 116 105 108 115
# Welcome to C++ Utils
Leap Year leap-year
Checks one or more years are leap or not
mkdir build && cd build
cmake ..
make
Run the program entering one or more years as parameter.
./leap-year 1900 2019 2400 2020
1900 is NOT a leap year.
2019 is NOT a leap year.
2400 is a leap year.
2020 is a leap year.