
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ program to append content of one text file to another
This is a C++ program to append the content of one text file to another.
Input
a.txt file contains “Tutorials” a1.txt file contains “point”
Output
Tutorialspoint
Algorithm
Begin 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 Code
#include <bits/stdc++.h> #include<fstream> using namespace std; int main() { fstream f; ifstream fin; fin.open("a.txt"); ofstream fout; fout.open("a1.txt", ios::app); if (!fin.is_open()) { cout << "Tutorialspoint"; } else { fout << fin.rdbuf(); } string word; f.open("a1.txt"); while (f >> word) { cout << word << " "; } return 0; }
Output
Tutorialspoint
- Related Articles
- C# Program to Append Text to an Existing File
- How to append text to a text file in C++?
- Java Program to Append Text to an Existing File
- C program to copy the contents of one file to another file?
- How to Append Text from One Cell to Another in Excel?
- Python Program to Append a String or Text to an Existing File
- Golang program to copy one file into another file
- 8086 program to add the content of one segment to another segment
- How to add/append content to an existing file using Java?
- C Program for copying the contents of one file into another file
- How to Copy Odd Lines of Text File to Another File using Python
- C# Program to Read the Content of a File Line by Line
- How to Append Contents of Multiple Files Into One File on Linux?
- Golang Program to open a file in append mode
- How to copy the content of one HTML5 Canvas to another Canvas locally?

Advertisements