
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7197 Articles for C++

2K+ Views
In C++ file handling, the tellp() function is used with output streams, and returns the current put position of the pointer in the stream. It returns an integer data type, representing the current position of the stream pointer.tellp() method takes no parameter. It is written as: pos_type tellp();AlgorithmBegin. Create an object newfile against the class fstream. Call open() method to open a file “tpoint.txt” to perform write operation using object newfile. Insert data into the file object newfile. Call the tellp() method to print the present position of the pointer in the file object. Call ... Read More

26K+ Views
This is a C++ program to read file line by line.Inputtpoint.txt is having initial content as "Tutorials point."OutputTutorials point.AlgorithmBegin Create an object newfile against the class fstream. Call open() method to open a file “tpoint.txt” to perform write operation using object newfile. If file is open then Input a string “Tutorials point" in the tpoint.txt file. Close the file object newfile using close() method. Call open() method to open a file “tpoint.txt” to perform read operation using object newfile. If file is open then Declare a ... Read More

12K+ Views
This is a C++ program to read data from a text file.Inputtpoint.txt is having initial content as “Tutorials point.”OutputTutorials point.AlgorithmBegin Create an object newfile against the class fstream. Call open() method to open a file “tpoint.txt” to perform write operation using object newfile. If file is open then Input a string “Tutorials point" in the tpoint.txt file. Close the file object newfile using close() method. Call open() method to open a file “tpoint.txt” to perform read operation using object newfile. If file is open then Declare ... Read More

1K+ Views
In C language, file handling is used for various file actions such as to write, read, merge, etc. Merging Contents of Two Files into a Third FileTo merge the contents of two files into a third file, you need to open the first two files (whose content will be merged into the third file) in read mode and the third file in write mode. After opening the files, read the contents of the first file and write them to the third file, and similarly with the second file and appending them to the third file. Example Scenario Imagine these are ... Read More

75K+ Views
In C++, you can read data from a text file using file handling features provided by the header. This is useful when you want your program to read input stored in a file instead of typing it every time. To do this, you use a special object called ifstream (input file stream), which helps your program open the file and read its contents line by line or word by word. Reading a text file is helpful when: You want to process saved data (like scores, settings, or logs). You want to ... Read More

7K+ Views
Appending text means adding new content to an existing file without removing its current content. In C++, this can be done by opening the file in append mode and writing the specified content to it. Steps to Append Text to a Text File You need to follow the below steps to open a file in append mode and append the content to it: First of all, you need to include the header file. Them, create an ofstream object to write to the file. Open the file in append mode using the ios::app flag. Use the

1K+ Views
In C++, we can work with files to read, write, or even combine(append) their contents. Here, our task is to append the content of one text file to another. Imagine a scenario where we have two txt files which is named as 'source.txt' and 'destination.txt' files. So, with the help of these files we need to copy everything from the source file and append it at the end of the destination file. ExampleHere, we are giving an input as two text files as source.txt and destination.txt to append content in C++: source.txt file contains "Tutorials" destination.txt file contains "point" ... Read More

540 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 different ways. Initially, we will create a global variable, then we will store the returned value of the printf() function into that variable. When printf() is executed, then it will be printed. You can print "Hello World" without using the logic inside the main() function in different ways, such as using Global Constructors, Class Object and macros, or preprocessor, etc. Using Global Constructor A global constructor is the constructor of a global object ... Read More

2K+ Views
The size of a file refers to the number of bytes it occupies in memory. In C, size of a file can be found by moving the file pointer to the end of the file and checking its position. The position indicates the number of bytes the file contains. The most common way to do this is by using two functions: fseek() (to move to the end) and ftell() (to get the current position, which is the size of the file). Syntax Following is the syntax is as follows: FILE *fp = fopen("file.txt", "rb"); fseek(fp, 0, SEEK_END); long size = ... Read More

174 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