Advertisement

Reading a file

Started by February 15, 2000 08:39 AM
2 comments, last by kp 24 years, 10 months ago
Hi everyone! I''m having some problems while reading standard text files. I wont the data from a line in the file to be copied into an array like char[n]. Does anyone have any samples that I can look at?
Straight from a book on C++:

#include <fstream.h>int main(void){  // A buffer for reading a line  char buffer[256];   // open the file for reading  ifstream fin("file.txt");   // read a line from the file with a   // maximum of 256 characters read  fin.getline(buffer, 256);   // Print the line to the screen  cout << buffer;   // exit the program  return 0; }
Advertisement
If you''d rather use C style file i/o, you can use the fgets() function to read full lines from a file.
You know, this can be found in every programming book ever written... I think it is right after "Hello World"...

This topic is closed to new replies.

Advertisement