Reading a file
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; }
If you''d rather use C style file i/o, you can use the fgets() function to read full lines from a file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement