Skip to content

Instantly share code, notes, and snippets.

@timpulver
Created March 19, 2012 19:32
Show Gist options
  • Save timpulver/2125363 to your computer and use it in GitHub Desktop.
Save timpulver/2125363 to your computer and use it in GitHub Desktop.
Read a textfile line after line
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
ifstream f; // Datei-Handle
string s;
f.open(argv[1], ios::in); // Öffne Datei aus Parameter
while (!f.eof()) // Solange noch Daten vorliegen
{
getline(f, s); // Lese eine Zeile
cout << s << endl; // Zeige sie auf dem Bildschirm
}
f.close(); // Datei wieder schließen
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment