View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12829 Members
Join this group to post and comment.
jigneshdgreat
jigneshdgreat • Jan 20, 2012

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??
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. 😀
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;
}

Share this content on your social channels -