Server Side Programming Articles - Page 2261 of 2650

How to determine the version of the C++ standard used by the compiler?

Samual Sam
Updated on 30-Jul-2019 22:30:26

4K+ Views

Sometimes we need to know that, what is the current C++ standard. To get this kind of information, we can use the macro called __cplusplus. For different standards, the value of this will be like below.Standard__cplusplus outputC++ pre C++981C++98199711LC++98 + TR1This cannot be checked, this will be marked as C++98C++11201103LC++14201402LC++17201703LExample#include int main() {    if (__cplusplus == 201703L)       std::cout

How to output colored text to a Linux terminal?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

8K+ Views

Here we will see how to print some lines into the linux terminal with some color. Here we are doing anything special into C++ code. We are just using some linux terminal commands to do this. The command for this kind of output is like below.\033[1;31m Sample Text \033[0mThere are some codes for text styles and colors. These are listed below.ColorForeground CodeBackground CodeBlack3040Red3141Green3242Yellow3343Blue3444Magenta3545Cyan3646White3747Some additional options are like below −OptionCodeDescriptionReset0Back to normal (remove all styles)Bold1Bold the textUnderline4Underline textInverse7Interchange colors of background and foregroundBold off21Normal from boldUnderline off24Normal from UnderlineInverse off27Reverse of the InverseExample#include using namespace std; main() {    cout Read More

What is difference between instantiating a C++ object using new vs. without new?

Samual Sam
Updated on 30-Jul-2019 22:30:26

8K+ Views

In C++, we can instantiate the class object with or without using the new keyword. If the new keyword is not use, then it is like normal object. This will be stored at the stack section. This will be destroyed when the scope ends. But for the case when we want to allocate the space for the item dynamically, then we can create pointer of that class, and instantiate using new operator.In C++, the new is used to dynamically allocate memory.Example#include using namespace std; class Point {    int x, y, z;    public:       Point(int x, ... Read More

How to get time in milliseconds using C++ on Linux?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

5K+ Views

Here we will see how to get time (the elapsed time for the program or any other kind of time).Here we are using linux library for C++. There is a structure called timeval. This timeval stores the time in seconds, milliseconds. We can create two time for start and end, then find the difference from them.Example#include #include #include using namespace std; main() {    struct timeval start_time, end_time;    long milli_time, seconds, useconds;    gettimeofday(&start_time, NULL);    cout > ch;    gettimeofday(&end_time, NULL);    seconds = end_time.tv_sec - start_time.tv_sec; //seconds    useconds = end_time.tv_usec - start_time.tv_usec; //milliseconds ... Read More

Handling large numbers in C++?

Samual Sam
Updated on 30-Jul-2019 22:30:26

12K+ Views

In C++, we can use large numbers by using the boost library. This C++ boost library is widely used library. This is used for different sections. It has large domain of applications. For example, using boost, we can use large number like 264 in C++.Here we will see some examples of boost library. We can use big integer datatype. We can use different datatypes like int128_t, int256_t, int1024_t etc. By using this we can get precision up to 1024 easily.At first we are multiplying two huge number using boost library.Example#include #include using namespace boost::multiprecision; using namespace std; int128_t large_product(long ... Read More

Generate random numbers following a normal distribution in C/C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

2K+ Views

Here we will see how to generate random numbers, which are following in a normal distribution. For the normal random, the formula is like below.𝑧 = √−2 ln 𝑥1 cos (2𝜋𝑥2)Here x1 and x2 are chosen randomly.Example#include #include #include #include using namespace std; double rand_gen() {    // return a uniformly distributed random value    return ( (double)(rand()) + 1. )/( (double)(RAND_MAX) + 1. ); } double normalRandom() {    // return a normally distributed random value    double v1=rand_gen();    double v2=rand_gen();    return cos(2*3.14*v2)*sqrt(-2.*log(v1)); } main() {    double sigma = 82.0;    double Mi = 40.0;    for(int i=0;i

How to get memory usage at runtime using C++?

Samual Sam
Updated on 30-Jul-2019 22:30:26

8K+ Views

We can get the memory usage like virtual memory usage or resident set size etc. at run time. To get them we can use some system libraries. This process depends on operating systems. For this example, we are using Linux operating system.So here we will see how to get the memory usage statistics under Linux environment using C++. We can get all of the details from “/proc/self/stat” folder. Here we are taking the virtual memory status, and the resident set size.Example#include #include #include #include #include using namespace std; void mem_usage(double& vm_usage, double& resident_set) {   ... Read More

Working with Images in Python?

George John
Updated on 30-Jul-2019 22:30:26

3K+ Views

One of the most popular and considered as default library of python for image processing is Pillow. Pillow is an updated version of the Python Image Library or PIL and supports a range of simple and advanced image manipulation functionality. It is also the basis for simple image support in other Python libraries such as sciPy and Matplotlib.Installing PillowBefore we start, we need python and pillow. Incase of Linux, pillow will probably be there already, since major flavour of linux including Fedora, Debian/Ubuntu and ArchLinux includes Pillow in packages that previously contained PIL.The easiest way to install it is to ... Read More

Short Circuiting Techniques in Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

2K+ Views

A common mistake for people new to programming is a misunderstanding of the way that boolean operators works, which stems from the way the python interpreter reads these expressions. For example, after initially learning about "and " and "or" statements, one might assume that the expression X = (‘x’ or ‘y’) would check to see if the variable X was equivalent to one of the strings ‘a’ or ‘b’. This is not so. To understand, what i’m trying to say, start an interactive session with the interpreter and enter the following expressions:>>> 'x' == ('x' or 'y') True >>> 'y' ... Read More

NZEC error in Python?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

908 Views

NZEC is non-zero exit code.Exit codes are codes (number) return by running program to operating system upon either their successfully termination (Exit code 0) or failed termination due to error (Non zero exit code).As python or Java programming language supports exception handling, we can use exception handling using try-catch blocks to catch this error.NZEC error is a runtime error and occurs mostly when negative array index is accesed or the program which we have written is utilizing more memory space than the allocated memory for our program to run.In python Exception class is the super class of all the errors ... Read More

Advertisements