|
|
| Ruminations on C++: A Decade of Programming Insight and Experience (ISBN: 0201423391) |
 |
List Price: $34.99
Our Price: $34.99
Used Price: $19.00
Release Date: 07 August, 1996
Manufacturer: Addison-Wesley Pub Co (Paperback)
Sales Rank: 94,760
Author: Andrew Koenig, Barbara E. Moo
|
More Info
|
|
|
Read from File
|
2002-01-31 16:57:04
|
| |
cpp
|
|
|
|
|
Category: source:cpp:files
|
|
Description: Shows how to read text in from a file in c++
|
|
Platform: unix/win
|
|
Author: detour
|
|
Viewed: 5457
|
|
Rating: 4/5 (42 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
/* fileread.cpp by detour@metalshell.com
*
* Example of reading a text file.
*
* http://www.metalshell.com/
*/
#include <iostream>
#include <fstream.h>
int main() {
char inLine[128];
char fname[24];
ifstream inFile;
cout << "Enter a file that contains text: ";
cin >> fname;
/* open the file */
inFile.open(fname, ios::in);
/* if opening didn't fail */
if(!inFile.fail()) {
while(!inFile.eof()) {
inFile >> inLine;
cout << inLine << endl;
}
inFile.close();
} else
cout << "Error Opening File.";
return 0;
}
|
|
|