- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
This is an simple way to read an entire file into std::string in C++AlgorithmBegin Take the filename as inputstream. Declare a string variable str. Read the file till the end by using rdbuf(). Put the data into st. Print the data. End.Example Code#include #include #include #include using namespace std; int main() { ifstream f("a.txt"); string str; if(f) { ostringstream ss; ss
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
60K+ Views
Writing To write a binary file in C++ use write() method. It is used to write a given number of bytes on the given stream, starting at the position of the "put" pointer. The file is extended if the put pointer is currently at the end of the file. If this pointer points into the middle of the file, characters in the file are overwritten with the new data. If any error has occurred during writing in the file, the stream is placed in an error state. Syntax of write() method ostream& write(const char*, int); Reading To read a binary ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
12K+ Views
Let us consider the following C++ sample code to get the list of files in a directory.AlgorithmBegin Declare a poniter dr to the DIR type. Declare another pointer en of the dirent structure. Call opendir() function to open all file in present directory. Initialize dr pointer as dr = opendir("."). If(dr) while ((en = readdir(dr)) != NULL) print all the file name using en->d_name. call closedir() function to close the directory. End.Example#include #include #include using namespace std; int main(void) { DIR ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
496 Views
Null pointer is a pointer which points nothing.Some uses of null pointer are:b) To initialize a pointer variable when that pointer variable isn’t assigned any valid memory address yet.b) To pass a null pointer to a function argument when we don’t want to pass any valid memory address.c) To check for null pointer before accessing any pointer variable. So that, we can perform error handling in pointer related code e.g. dereference pointer variable only if it’s not NULL.In C++ if we assign 0 in any pointer that means the pointer pointing to the NULL.SyntaxFloat *p = 0 //initializing the pointer ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
518 Views
If a binary tree is traversed in-order, the left subtree is visited first, then the root and later the right sub-tree. The output the key in ascending order in in_order traversal. This is a C++ Program for Inorder Tree Traversal without Recursion.AlgorithmBegin Function inOrder(): Declare a stack s. Declare the current node as root. While current node is not null and stack is not empty do While current node is not null do Push the current node on the ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
415 Views
Different operations on array and pseudocodes:Begin In main(), While TRUE do Prints some choices. Take input of choice. Start the switch case When case is 1 Print the size of the array. Break When case is 2 Insert the values in array. Break When case is 3 Print ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
4K+ Views
vector::begin() function is a bidirectional iterator used to return an iterator pointing to the first element of the container.vector::end() function is a bidirectional iterator used to return an iterator pointing to the last element of the container.AlgorithmBegin Initialize the vector v. Declare the vector v1 and iterator it to the vector. Insert the elements of the vector. Print the elements. End.Example Code Live Demo#include #include using namespace std; int main() { vector v = { 50, 60, 70, 80, 90}, v1; //declaring v(with values), v1 as vector. vector::iterator it; //declaring an ierator ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
662 Views
vector insert() function in C++ STL helps to increase the size of a container by inserting the new elements before the elements at the specified position.It is a predefined function in C++ STL.We can insert values with three types of syntaxes1. Insert values by mentioning only the position and value:vector_name.insert(pos, value);2. Insert values by mentioning the position, value and the size:vector_name.insert(pos, size, value);3. Insert values in another empty vector form a filled vector by mentioning the position, where the values are to be inserted and iterators of filled vector:empty_eector_name.insert(pos, iterator1, iterator2);AlgorithmBegin Declare a vector v with values. Declare ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
99 Views
unordered_multimap swap() function in C++ STL is used to swap the elements of one multimap to another of same size and type.AlgorithmBegin Declaring two empty map container m, m1. Insert some values in both m, m1 map containers. Perform swap() function to swap the values of m, m1 map containers. Printing the swapped values of m map container. Printing the swapped values of m1 map container. End.Example Code Live Demo#include #include using namespace std; int main() { unordered_map m, m1; // declaring m, m1 as empty map container m.insert (pair('b', 10)); ... Read More