Extract text from a File || File Handling || C++
In this we are going to see a program of File Handling to extract text from files in C++ Programming Language. 
 


The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include <fstream.h>
#include<conio.h>

void main()
{
    ifstream f;
    char line;
    f.open("xyz.txt");
    getline(f,line);
    cout << line;
    if (f)
    {
	cout << "\nSuccessfully retrieved from the file";
    }
    else
    {
        cout << "Nope";
    }
    f.close();
    getch();
}

//.......Coded by SAHIL SHAIKH


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream f;
    string line;
    f.open("xyz.txt");
    getline(f, line);
    cout << line;
    if (f.is_open())
    {
        cout << "\nSuccessfully retrieved from the file";
    }
    else
    {
        cout << "Nope";
    }
    f.close();
}

//.......Coded by SAHIL SHAIKH

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post