Found 7347 Articles for C++

strtol() function in C++

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

244 Views

The strol() function is used to convert the string to long integers. It sets the pointer to point to the first character after the last one. The syntax is like below. This function is present into the cstdlib library.long int strtol(const char* str, char ** end, int base)This function takes three arguments. These arguments are like below −str: This is the starting of a 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, ... Read More

ldexp() function in C/C++

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

124 Views

Here we will see what is the use of ldexp() method in C or C++. This function returns any variable x raise to the power of exp value. This takes two arguments x and exp.The syntax is like below.float ldexp (float x, int exp) double ldexp (double x, int exp) long double ldexp (long double x, int exp) double ldexp (T x, int exp)Now let us see one example to get a better idea.Example#include #include using namespace std; int main() {    double a = 10, res;    int exp = 2;    res = ldexp(a, exp); // Finds a*(2^exp)    cout

Preventing Object Copy in C++

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

202 Views

In C++, when classes are created, we can copy it using some copy constructor or assignment operator. In this section we will see, how to prevent object copy of a class in C++. To prevent object copy, we can follow some rules. These are like below.1. Creating private copy constructor and private assignment operator.Example#include using namespace std; class MyClass {    int x;    public:       MyClass() {          //non-parameterized constructor       }       MyClass(int y): x(y) {       }    private:       MyClass(const MyClass& obj) ... Read More

Advanced C++ with boost library

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

1K+ Views

C++ boost libraries are widely useful 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 long n1, long long n2) {    int128_t ans = (int128_t) n1 * ... Read More

Object Slicing in C++

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

380 Views

Object slicing is used to describe the situation when you assign an object of a derived class to an instance of a base class. This causes a loss of methods and member variables for the derived class object. This is termed as information being sliced away. For example, class Foo {    int a; }; class Bar : public Foo {    int b; }Since Bar extends Foo, it now has 2 member variables, a and b. So if you create a variable bar of type Bar and then create a variable of type Foo and assign bar, you'll lose ... Read More

transform() in C++

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

3K+ Views

The transform function is present in the C++ STL. To use it, we have to include the algorithm header file. This is used to perform an operation on all elements. For an example if we want to perform square of each element of an array, and store it into other, then we can use the transform() function.The transform function works in two modes. These modes are −Unary operation modeBinary operation modeUnary Operation ModeIn this mode the function takes only one operator (or function) and convert into output.Example#include #include using namespace std; int square(int x) {    //define square ... Read More

What is NaN in C++?

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

737 Views

The NaN is the abbreviation of Not a Number. It indicates undefined or non-representable floating point elements. One example of NaN is square root of some negative number, or result of 0/0.Example#include #include using namespace std; int main() {    cout >> "Square root of -5: " >> sqrt(-5) >> endl; }OutputSquare root of -5: nan

What does buffer flush means in C++ ?

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

1K+ Views

The buffer flush is used to transfer of computer data from one temporary storage area to computers permanent memory. If we change anything in some file, the changes we see on the screen are stored temporarily in a buffer.In C++, we can explicitly have flushed to force the buffer to be written. If we use std::endl, it adds one new line character, and also flush it. If this is not used, we can explicitly use flush. In the following program at first no flush is used. Here we are trying to print the numbers, and wait for one seconds. For ... Read More

regex_error in C++

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

166 Views

The regex library has different methods and features related to regular expressions. Here we will see some regex_errors. These are also present at regex library. During executing some regular expressions, we get some errors. That errors are mentioned here.FlagsErrorserror_collateIn the Regex, the names having invalid collation.error_ctypeIn the Regex, there is an invalid character class name.error_stackNot enough memory to determine regex can be matched or not.error_spaceConvert into Finite State Machine, when memory is insufficienterror_badrepeatThe string has repeat specifier ( *?+{) that was not preceded by a valid regular expression.error_complexityThe complexity of an attempted match against a regex exceeded a pre-set levelerror_rangeContaining ... Read More

C qsort() vs C++ sort()

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

410 Views

Here we will see what are the differences between qsort() in C, and sort() in C++.The C provides qsort() function, that can be used for sorting an array. The function arguments and syntax is like below.void qsort(void *base, size_t num, size_t size, int (*comparator) (const void*, const void*));This function takes the base address of that array, the number of elements of that array. Size of each item in the array, and a comparator function.The C++ provides sort() function. This is present inside C++ STL. The arguments and syntax is like below.void sort(T first, T last, Compare c);Here the order of ... Read More

Advertisements