C++ Articles

Page 578 of 597

Generalized Lambda Expressions in C++14

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 386 Views

In C++11, the lambda was introduced. Lambdas are basically a part of code, that can be nested inside other function call statements. By combining lambda expressions with the auto keyword, they can be used later.In C++14, these lambda expressions are improved. Here we can get the generalized lambda. For example, if we want to create a lambda, that can add integers, add numbers, also concatenate strings, then we have to use this generalized lambda.Syntax of the lambda expression is looking like this:[](auto x, auto y) { return x + y; }Let us see one example to get the better idea.Example#include ...

Read More

Reverse a string in C/C++ using Client Server model

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 1K+ Views

Here we will see how we can create a system, where we will create one client, and a server, and the client can send one string to the server, and the server will reverse the string, and return back to the client.Here we will use the concept of socket programming. To make the client server connection, we have to create port. The port number is one arbitrary number that can be used by the socket. We have to use the same port for client and the server to establish the connection.To start the program, start the server program first −gcc ...

Read More

The best way to hide a string in binary code in C++?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 697 Views

Here we will see how to hide some string into some binary code (Here binary code is represented in hexadecimal number).The approach is very simple. We can use the string stream to convert decimal number to hexadecimal numbers. Now from the string, we will read each character, and take its ASCII value, these ASCII values are converted into hexadecimal values. Then we can print them one by one.Example#include #include using namespace std; string dec_to_hex(int decimal){ //function is used to convert decimal to hex    stringstream my_ss;    my_ss

Read More

What's the best way to trim std::string in C++?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 11K+ Views

Here we will see how to trim the strings in C++. The trimming string means removing whitespaces from left and right part of the string.To trim the C++ string, we will use the boost string library. In that library, there are two different methods called trim_left() and trim_right(). To trim string completely, we can use both of them.Example#include #include using namespace std; main(){    string myStr = " This is a string ";    cout

Read More

What is the most effective way for float and double comparison in C/C++?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 8K+ Views

Here we will see how to compare two floating point data or two double data using C or C++. The floating point / double comparison is not similar to the integer comparison.To compare two floating point or double values, we have to consider the precision in to the comparison. For example, if two numbers are 3.1428 and 3.1415, then they are same up to the precision 0.01, but after that, like 0.001 they are not same.To compare using this criteria, we will find the absolute value after subtracting one floating point number from another, then check whether the result is ...

Read More

What is the difference between const int*, const int * const, and int const *?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 643 Views

Here we will see some different types of variable declaration based on integer pointers integer constants and the integer constant pointers.To determine them we will use the Clockwise/Spiral Rule. By discussing the terms, we can understand the rules also.The const int *. This is used to tell the compiler that this is a pointer type variable, and this can store address of some constant int. The Clock rule is saying like this −Now the another one is const int * const. This is used to denote that this is one constant pointer variable, which can store the address of another ...

Read More

What is the effect of extern "C" in C++?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 3K+ Views

The extern “C” keyword is used to make a function name in C++ have the C linkage. In this case the compiler does not mangle the function. Let us see what is the mangling in C++ first, then we can discuss about the extern “C” keyword.In C++ we can use the function overloading feature. Using this feature, we can create functions with same name. The only difference is the type of the arguments, and the number of arguments. The return type is not considered here. Now the question comes how the C++ distinguishes overloaded functions in object code?In the object ...

Read More

Is there a difference between copy initialization and direct initialization in C++?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 3K+ Views

The Copy initialization can be done using the concept of copy constructor. As we know that the constructors are used to initialize the objects. We can create our copy constructor to make a copy of some other object, or in other words, initialize current object with the value of another object. On the other hand, the direct initialization can be done using assignment operation.The main difference between these two types of initialization is that the copy initialization creates a separate memory block for the new object. But the direct initialization does not make new memory space. It uses reference variable ...

Read More

When should I write the keyword 'inline' for a function/method in C++?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 190 Views

In C++, the inline keyword is used in different places. To create inline variables, or inline namespace, and as well as to create inline methods or functions.C++ inline function is powerful concept that is commonly used with classes. If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.Any change to an inline function could require all clients of the function to be recompiled because compiler would need to replace all the code once again otherwise it will continue with old functionality.To inline a ...

Read More

How do I convert between big-endian and little-endian values in C++?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 7K+ Views

Here we will see how to convert Little endian value to Big endian or big endian value to little endian in C++. Before going to the actual discussion, we will see what is the big endian and the little endian?In different architectures, the multi-byte data can be stored in two different ways. Sometimes the higher order bytes are stored first, in that case these are known as big endian, and sometimes the lower order bytes are stored first, then it is called little endian.For example, if the number is 0x9876543210, then the big endian will be −The little endian will ...

Read More
Showing 5771–5780 of 5,962 articles
« Prev 1 576 577 578 579 580 597 Next »
Advertisements