- 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 7401 Articles for C++
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
279 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
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
112 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
334 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
128 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
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
375 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
825 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
539 Views
The C/C++ library function double log(double x) returns the natural logarithm (basee logarithm) of x. Following is the declaration for log() function.double log(double x)The parameter is a floating point value. And this function returns natural logarithm of x.Example Live Demo#include #include using namespace std; int main () { double x, ret; x = 2.7; /* finding log(2.7) */ ret = log(x); cout
To Continue Learning Please Login
Login with Google