Code Monkey home page Code Monkey logo

utilscpp's Introduction

C++ Utils Terminal Root

./utilscpp

My C++ Utility Library

C++ Utils Terminal Root


Colors C++ colors

Library to print your strings with a single function (object)

How to use

    1. Add the library and vector to your header
#include <vector>
#include "libcolors.h"
    1. Instantiate the class
Colors c;
    1. 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;
}

Ready example

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

Help

Use the -h or --help option to see available colors and other information. Exemplo:

./colors --help

Easily add help to your program

How to use

    1. Include library header
#include "help.hh"

If it is on a different path, indicate the full path, for example: #include "path/to/help.hh"

    1. Pass the command line arguments: int argc and char** argv to the main() function, for example:
    1. Instantiate the Help class and call the help.m_help (argc, argv) and m_dhelp() methods/members, for example:
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

Convert decimal to binary

Compiling

mkdir build && cd build
cmake ..
make
./dec2bin 81
1010001

Convert binary to decimal

Compiling

mkdir build && cd build
cmake ..
make
./bin2dec 111010
# 58

Alternatively use GNU Make

./bin2dec 10110
# 22

Convert decimal to hexadecimal

Compiling

mkdir build && cd build
cmake ..
make
./dec2hex 8041979
# 7AB5FB
./dec2hex 13021952
# C6B300

Convert hexadecimal to decimal

Compiling

make
./hex2dec A82EB9
# 11022009
./hex2dec 10542C5
# 17121989

Convert ASCII to decimal

Compiling

mkdir build && cd build
cmake ..
make

Use

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

Compiling

mkdir build && cd build
cmake ..
make

Use

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

Compiling

mkdir build && cd build
cmake ..
make

Use

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.

By Marcos Oliveira

By https://en.terminalroot.com.br

utilscpp's People

Contributors

terroo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.