C++ Articles - Page 697 of 719

What is "Argument-Dependent Lookup" ("Koenig Lookup") in C++?

Chandu yadav
Updated on 12-Feb-2020 06:34:31

355 Views

Argument-dependent lookup(ADL) is a protocol for looking up unqualified function names in function-call expressions.These function call expressions include implicit function calls to overloaded operators.The function names are looked up in the namespaces of their arguments in addition to the scopes and namespaces considered by the usual unqualified name lookup. Argument-dependent lookup makes it possible to use operators defined in a different namespace. Examplenamespace MyNamespace{    class A {};    void f( A &a, int i) {} } int main() {    MyNamespace::A a;    f( a, 0 );    //calls MyNamespace::f }The lookup of a function call to f was dependent ... Read More

What's the difference between "STL" and "C++ Standard Library"?

Govinda Sai
Updated on 24-Jun-2020 06:31:32

2K+ Views

The Standard Template Library (STL) is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called algorithms, containers, functions, and iterators. Note that the term "STL" or "Standard Template Library" does not show up anywhere in the ISO 14882 C++ standard. So referring to the C++ standard library as STL is wrong, ie, STL and C++ Standard Library are 2 different things with the former being the subset of the latter.The STL consists ofContainersThe STL contains sequence containers and associative containers. Containers are objects that store data. The ... Read More

Why should C++ programmers minimize use of 'new'?

Ankith Reddy
Updated on 02-Mar-2020 08:07:45

139 Views

new is used for dynamic memory allocation. The memory allocated in this case goes on the heap. There are several costs associated with this type of memory allocation along with the programmer having to do manual memory cleaning and management. This type of allocation must be used when − You don't know how much memory you need at compile time.You want to allocate memory which will persist after leaving the current block.Other than these, there are very few cases where dynamic memory allocation is required. This is because, in C++, there is the concept of a destructor. This function gets called ... Read More

What is a "translation unit" in C++

Srinivas Gorla
Updated on 30-Jul-2019 22:30:22

3K+ Views

A translation unit is any preprocessed source file.A translation unit is the basic unit of compilation in C++. This unit is made up of the contents of a single source file after it passes through preprocessing. It contains included any header files without blocks that are ignored using conditional preprocessing statements like ifdef, ifndef, etc.A single translation unit can be compiled into an object file, library, or executable program.

Read whole ASCII file into C++ std::string

George John
Updated on 03-Dec-2024 09:40:15

15K+ Views

This is a simple way to read whole ASCII file into std::string in C++ − Algorithm Here is the algorithm we will follow to Read the whole ASCII file into C++ std::string. Begin  Declare a file a.txt using file object f of ifstream type to perform a read operation.  Declare a variable str of string type.  If(f) Declare another variable ss of ostringstream type. Call rdbuf() function to read the data of the file object. Put the ... Read More

List of Common Reasons for Segmentation Faults in C/C++

Ramu Prasad
Updated on 27-Jan-2020 12:38:34

5K+ Views

The main reason for segmentation fault is accessing memory that is either not initialized, out of bounds for your program or trying to modify string literals. These may cause a segmentation fault though it is not guaranteed that they will cause a segmentation fault. Here are some of the common reasons for segmentation faults −Accessing an array out of boundsDereferencing NULL pointersDereferencing freed memoryDereferencing uninitialized pointersIncorrect use of the "&" (address of) and "*" (dereferencing) operatorsImproper formatting specifiers in printf and scanf statementsStack overflowWriting to read-only memory

Difference between private, public, and protected modifiers in C++

Nikitha N
Updated on 24-Jun-2020 06:33:56

7K+ Views

Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled access modifiers − public, private, and protected sections within the class body.The default access for members and classes is private.Exampleclass Base { public:    // public members go here protected:    // protected members go here private:    // private members go here };A public member is accessible from anywhere outside the class but within a program. ... Read More

How do I print a double value with full precision using cout in C++?

Arjun Thakur
Updated on 24-Jun-2020 06:34:50

2K+ Views

The output stream cout allows using manipulators that you can use to set the precision directly on cout and use the fixed format specifier. To get the full precision of a double, you can use the limits library. For example,Example#include #include using namespace std; int main() {     // Get numeric limits of double     typedef std::numeric_limits< double > dbl;     double PI = 3.14159265358979;     cout.precision(dbl::max_digits10);     cout

How to convert an std::string to const char* or char* in C++?

Sravani S
Updated on 12-Feb-2020 06:30:54

19K+ Views

You can use the c_str() method of the string class to get a const char* with the string contents. example#include using namespace std; int main() {    string x("hello");    const char* ccx = x.c_str();    cout

How does the compilation/linking process work in C/C++?

Chandu yadav
Updated on 27-Jan-2020 12:37:53

5K+ Views

The compilation of a C++ program consists of three steps −Preprocessing − In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. It handles preprocessing directives like #include, #define, etc.Compilation − The compilation takes place on the preprocessed files. The compiler parses the pure C++ source code and converts it into assembly code. This in turn calls the assembler that converts the assembly code to machine code(binary) as Object files. These Object files can refer to symbols that are not defined. The compiler won't give ... Read More

Advertisements