Using Code to Open a File and Read from It - C++ File Stream

C++ examples for File Stream:stream

Description

Using Code to Open a File and Read from It

Demo Code

#include <iostream> 
#include <fstream> 
#include <string> 

using namespace std; 

int main() //  w  w  w .j  ava 2 s  .  co  m
{ 
    string word; 
    ifstream infile("../MyFile.txt"); 
    infile >> word; 
    cout << word << endl; 
    infile.close(); 

    return 0; 
}

Result


Related Tutorials