WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   getline verständnisprobleme :( (http://www.wcm.at/forum/showthread.php?t=185252)

abcxyz 12.02.2006 01:17

getline verständnisprobleme :(
 
hallo!

muss ja schon lästig klingen, aber in meinem buch ist das getline relativ kurz gehalten leider.

ich will eine datei (textdatei) öffnen und via getline einlesen.
kann mir jemand ein beispiel tippseln mit kommentaren bei getline, welches es mir einfacher erklärt? hänge da nun schon seit tagen dran. :heul: *bettel* :)
z.B. ist mir das mit dem string nicht ganz klar und char* p und dem buffer und wie lange der sein _muss_ usw.

muss mal erwähnen welches buch ich besitze, weil es ist glaube ich kein einsteigerbuch: c++ einführung und professionelle programmierung (hanser)
es ist ja soweit n sehr gutes buch.

Biri 12.02.2006 17:47

Getline:

Get a line from stream.
Extracts characters from the stream and stores them into successive locations in the array pointed by s.
Characters are extracted until either (n - 1) characters have been extracted, the delimiter (parameter delim or '\n' if not specified) is found, or if the end of file or any error occurs in the input sequence.
If the delimiter is found it is extracted but not not stored. Use get if you don't want this character to be extracted.
An ending null character is automatically appended after the data stored in s.

PHP-Code:

 #include <fstream.h>
    
int main()
    {
        
char str[2000];
        
fstream file_op("c:\\test_file.txt",ios::in);  // textdatei öffnen
        
while(!file_op.eof())  // solange nicht dateiende
        
{
              
file_op.getline(str,2000);  // Zeile einlesen, max. 2000 zeichen oder bis zum 1. "\n"
              
cout <<str;  // gelesene zeile ausgeben
        
}         file_op.close();
        
cout <<endl;
        return 
0;
    } 

alles klar? ;)
...ist aber nicht sooo schwer in den weiten des internets zu finden.

fg
-hannes

abcxyz 13.02.2006 19:24

ah super danke!
die pufferlänge gehört also auch noch mal mit rein.


Alle Zeitangaben in WEZ +2. Es ist jetzt 08:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag