- 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)
7K+ Views
This is a C++ program to append text to a text file.AlgorithmBegin Open that file a1.txt as output file stream class object to perform output operation in append mode using fout file reference. If the file exists then Appending text to that file. Close fout. Open the file “a1.txt” for reading the content of the file. Extracting the text from file and printing the text. End.Example Code Live Demo#include #include #include using namespace std; int main() { fstream f; ofstream fout; ifstream fin; fin.open("a1.txt"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
This is a C++ program to append the content of one text file to another.Inputa.txt file contains “Tutorials” a1.txt file contains “point”OutputTutorialspointAlgorithmBegin Define a fstream class object as fin. Open a input file a.txt with input file stream class object fin. Open a output file a1.txt with output file stream class object fout in append mode. Check if the file is not existing then Print “File not found”. Else append content from fin to fout. Open the destination file in read mode. Display its content as output. End.Example ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
318 Views
In this problem we will see how to print “Hello World” into the console, but we cannot write anything into the main function.This problem can be solved in two different ways. In the first approach we will create a global variable, then we will store the returned value of printf() function into that variable. When printf() is executed, then it will be printed. See the code for better understanding.Example Live Demo#include using namespace std; int a = printf("Hello World"); int main() { }OutputHello WorldIn the next approach we will create a class, and print the line using the constructor of that ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
This is a C Program to find size of a File.AlgorithmBegin function findfileSize() Open a file pointer fp in read only mode. If fp is equals to null then Print “File not found” and return -1. Else count the file size. Close the file. Put the file pointer at the beginning of the file Declare a integer variable result and initialize it with the output of the ftell() function. Close file pointer fp. Return result. EndExample#include int findfileSize(char f_n[]) { FILE* fp = fopen(f_n, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
133 Views
This is a C++ Program to Find Size of the Largest Independent Set (LIS) in a Given a Binary Tree.AlgorithmBegin. Create a structure n to declare data d, a left child pointer l and a right child pointer r. Call a function max() to return maximum between two integers. Create a function LIS() to return the size of the largest independent set in a given binary tree. Calculate size excluding the current node int size_excl = LIS(root->l) + LIS(root->r) Calculate size including the current node int size_incl = 1; if (root->l) ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
351 Views
In this section we will see what are the differences between exit() and _Exit() in C and C++. In C the exit() terminates the calling process without executing the remaining code which is present after exit() function.In C++11, one new function is present called _Exit(). So what is the feature of this function? The exit() function performs some cleaning before terminating the program. It clears the connection termination, buffer flushes etc. This _Exit() function does not clean anything. If we test using atexit() method, it will not work.Let us see two examples where at first we are using exit() function, ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
143 Views
The C / C++ library function div_t div(int numer, int denom) divides numer (numerator) by denom (denominator). Following is the declaration for div() function.div_t div(int numer, int denom)The parameters are numerator and the denominator. This function returns the value in a structure defined in , which has two members. For div_t:int quot; int rem;Example Live Demo#include #include using namespace std; int main () { div_t output; output = div(27, 4); cout
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
A vector of a vector is called 2D vector.AlgorithmBegin Declare a variable v to the 2D vector type. Initialize values to the vector v. Print “the 2D vector is:”. for (int i = 0; i < v.size(); i++) for (int j = 0; j < v[i].size(); j++) print the value of 2D vector v[i][j]. End.Example Live Demo#include #include //header file for 2D vector in C++ using namespace std; int main() { vector v{ { 4,5, 3, 10 }, // initializing 2D vector with values. { 2, 7, 11 }, { 3, 2, 1, 12 } }; cout
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
394 Views
A binary tree which has at most two children, specified as left child and right child. This is a C++ Program to find the lowest common ancestor in a Binary Tree.AlgorithmBegin Create a structure n to declare data d, a left child pointer l and a right child pointer r. Create a function to create newnode. Call a function LCA() to Find lowest common ancestor in a binary tree: Assume node n1 and n2 present in the tree. If root is null, then return. If root is not null there are two cases. ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
873 Views
In this section we will see what is the purpose of memset() function in C++. This function converts the value of a character to unsigned character and copies it into each of first n character of the object pointed by the given str[]. If the n is larger than string size, it will be undefined.The syntax of the memset() functionvoid* memset( void* str, int c, size_t n);In this example will use one string, then convert each character to some other character up to length n.Example Live Demo#include using namespace std; int main() { char str[] = "Hello World"; memset(str, ... Read More