TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RICK SVYZEK
from: JERRY COFFIN
date: 1997-09-27 10:45:00
subject: File reading

On (23 Sep 97) Rick Svyzek wrote to All...
 RS>        Hi, I got a problem I been working on. I'm a beginner at C++
 RS>  programming. What I need help with is how to read a text file line by
 RS>  line with a program. I can get my program to open a file stream and
 RS>  it reads the first line then exits.  Could someone please point me
 RS> into  the right direction :)
A while loop is the most common method:
    ifstream file("whatever.txt");
    char buffer[256];
    while ( !file.bad() ) {
        file.getline(buffer, 256);
There's also a good() member function, but for better or worse, !bad()
is NOT the same as good(), nor vice versa...
    Later,
    Jerry.
--- PPoint 2.02
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.