How to give input to a c++ program from an input file ?

I know how to take input in c++ using standard console functions like cout and cin . But how can I use an external input file to give input to it??

Replies

  • Dancer_Engineer
    Dancer_Engineer
    jigneshdgreat
    I know how to take input in c++ using standard console functions like cout and cin . But how can I use an external input file to give input to it??
    To get input from a file, you will have to use ifstream to read data from files as input streams.
    To get output to a file, you will have to use ofstream to write data to files as output streams.

    Include this library: #include

    I hope that helps. 😀
  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    You can try using file handlers... Eg.:
    #include 
    int main ()
    {
      FILE * pFile;
      pFile = fopen ("myfile.txt","w");
      if (pFile!=NULL)
      {
        fputs ("fopen example",pFile);
        fclose (pFile);
      }
      return 0;
    }

You are reading an archived discussion.

Related Posts

If you are any app developer, you can join hands with ford. The American company is going to all lengths to attract hugh intellectual population to work with them. All...
Yes, the title is true! Ford has achieved what until now only European Luxury brands gave their customers. This quite interior effect is all because of Elliptical Acoustic Mirrors- Ford...
FFT or Fast Fourier Transform is an age old concept of digital implementation of DFT. Even after 50 years, FFT is kind of like nightmares to many engineers. So if...
CAn anyone tell me some very good intresting site about airplanes and aeronautics..........
Why shouldn't you use a "Rubber Glove" One of the worst things that you can do in this instance is to fit a rubber "glove" over the distributor, although this...