- 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 7399 Articles for C++
2K+ Views
Vectors have the ability to resize itself automatically like dynamic arrays when an element is inserted or deleted, the container handle their storage automatically.The main difference between vector resize() and vector reserve() is that resize() is used to change the size of vector where reserve() doesn’t. reserve() is only used to store at least the number of the specified elements without having to reallocate memory. But in resize() if the number is smaller than the current number then it resizes the memory and deletes the excess space over it.vector::resize()Vector resize() is used to change its size.ExampleSteps in the source code:Begin ... Read More
1K+ Views
The function tmpfile() creates a temporary file in binary update mode in C. It initializes in header file of a C program. It always returns a null pointer if the temporary file cannot be created. The temporary file deleted automatically just after the termination of program.SyntaxFILE *tmpfile(void)Return valueIf file creation is successful, the function returns a stream pointer to the temporary file created. If the file cannot be created, NULL pointer is returned.AlgorithmBegin. Declare an array variable c[] to the character datatype and take a character data string. Initialize a integer variable i ← 0. Declare a ... Read More
1K+ 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
25K+ 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
11K+ 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
804 Views
This is a c program to merge the contents of two files into the third file.For Example.Inputjava.txt is having initial content “Java is a programing language.” kotlin.txt is having initial content “ kotlin is a programing language.” ttpoint.txt is having initial content as blankOutputfiles are merged ttpoint.txt will have final content as “Java is a programing language. kotlin is a programing language.”AlgorithmBegin Declare a[] array to the character datatype. Initialize a[] = "Java is a programing language.". Declare i of the integer datatype. Initialize i =0. Declare f1 as a pointer ... Read More
56K+ Views
This is a C++ program to read 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 a string ... Read More
6K+ 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
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
To Continue Learning Please Login
Login with Google