Found 7347 Articles for C++

The feclearexcept in C++

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

40 Views

The feclearexcept() function is used to clear the supported floating point exceptions represented by the excepts.This function returns 0, if all exceptions are cleared, or the exception value is 0. And returns nonzero value for some exceptions.To use this function, we have to enable the FENV_ACCESS. This will give our program to access the floating point environment to test the exception raised.Example#include #include #include #pragma STDC FENV_ACCESS on using namespace std; main() {    feclearexcept(FE_ALL_EXCEPT);    sqrt(-5);    if (fetestexcept(FE_INVALID))       cout >> "sqrt(-5) will generate FE_INVALID" >> endl; }Outputsqrt(-5) will generate FE_INVALIDRead More

Any datatype in C++ boost library

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

169 Views

The boost library has large range of functionalities. The any datatype is one of them. Any datatype is used to store any type of values in variable. Some other languages like javascripts, python, we can get this kind of datatypes. In C++ we can get this feature only using boost library.Example#include "boost/any.hpp" #include using namespace std; main() {    boost::any x, y, z, a; //define some variable of any datatype    x = 20; //Store x as integer    cout >> "x : " >> boost::any_cast(x) >> endl; //display the value of x    y = 'A'; //Store y ... Read More

static_cast in C++

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

4K+ Views

The static_cast is used for the normal/ordinary type conversion. This is also the cast responsible for implicit type coercion and can also be called explicitly. You should use it in cases like converting float to int, char to int, etc. This can cast related type classes.Example#include using namespace std; int main() {    float x = 4.26;    int y = x; // C like cast    int z = static_cast(x);    cout >> "Value after casting: " >> z; }OutputValue after casting: 4If the types are not same it will generate some error.Example#include using namespace std; class Base ... Read More

Count the number of objects using Static member function in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

5K+ Views

Here we will see how to count number of objects are created from a specific class using some static member functions. The static members are class properties, not the object properties. For a single class there will be only one instance for static members. No new members are created for each objects.In this problem we are using one static counter variable to keep track the number of objects, then static member will be there to display the count value.When a new object is created, so the constructor will be called. Inside the constructor, the count value is increased. Thus we ... Read More

Middle of three using minimum comparisons in C++

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

464 Views

In this section, we will see how to find the middle of three given values by comparing them. So if three numbers are given like (10, 30, 20), then it will find 20 as this is the middle element. Let us see the algorithm first, then we will implement that algorithm into C++ code.Algorithmmiddle_of_three(a, b, c): Input: Three numbers a, b and c Output: The middle of these three Begin    if a > b, then       if b > c, then          return b       else if a > c, then   ... Read More

Why “using namespace std” is considered bad practice in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

2K+ Views

C++ has a standard library that contains common functionality you use in building your applications like containers, algorithms, etc. If names used by these were out in the open, for example, if they defined a queue class globally, you'd never be able to use the same name again without conflicts. So they created a namespace, std to contain this change.The using namespace statement just means that in the scope it is present, make all the things under the std namespace available without having to prefix std:: before each of them.While this practice is okay for example code, pulling in the ... Read More

sqrt, sqrtl and sqrtf in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

748 Views

In the cmath library of C++, there are different functions for getting the square root except from sqrt. The sqrt is used basically for double type input. The others are used for float, long type data etc. Let us see the usage of these functions.The sqrt() FunctionThis function is used for double type data. So this returns square root of type double. The syntax is like below.double sqrt(double argument)Example#include #include #include using namespace std; main() {    double x = 144.0;    double y = 180.0;    cout

abs(), labs(), llabs() functions in C/C++

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

118 Views

In the cstdlib library of C++, there are different functions for getting the absolute value except from abs. The abs are used basically for int type input in C, and int, long, long long in C++. The others are used for long, and long long type data etc. Let us see the usage of these functions.The abs() FunctionThis function is used for int type data. So this returns the absolute value of the given argument. The syntax is like below.int abs(int argument)Example#include #include #include using namespace std; main() {    int x = -145;    int y = 145;    cout

remainder() in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

146 Views

Here we will see the functionality of remainder() method of C++. The remainder() function is used to compute the floating point remainder of numerator/denominator.So the remainder(x, y) will be like below.remainder(x, y) = x – rquote * yThe rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. The first argument is numerator, and the second argument is the denominator.Example#include #include using namespace std; main() {    double x = ... Read More

wcstoll() function in C/C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

94 Views

The wcstoll() function is used to convert the wide character string to long long integers. It sets the pointer to point to the first character after the last one. The syntax is like below.long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)This function takes three arguments. These arguments are like below −str: This is the starting of a wide string.str_end: The str_end is set by the function to the next character, after the last valid character, if there is any character, otherwise null.base: This specifies the base. The base values can be of (0, 2, 3, …, 35, 36)This function ... Read More

Advertisements