F How to read TXT file content using CPP Program | CodeTheta

How to read TXT file content using CPP Program


Code : 
/*
* Author: Soumyodeep Mondal
*/

//header file to include all standard library header file
#include <bits/stdc++.h>
using namespace std;

int main() {
 
    //file stream declaration
    fstream txtfile;
    string stringcontent, targetfilename;
 
    //name of the file which we will read through cpp program
    targetfilename = "targetfile.txt";
 
    //open the targetfile.txt
    txtfile.open(targetfilename.c_str());
 
    //reading the string of the targetfile.txt
    while (txtfile >> stringcontent) {
        cout << stringcontent;
    }
    return 0;
}

Output :
www.codetheta.com

IDE Used To Test This Code : Dev C++

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment