![]() |
C/C++, KDEVELOP |
|---|
BasicsProgram FlowFunctionsClasses and ObjectsX WindowKDevelop----------------- © Alfred Nussbaumer Updated: 09 December 2021 ----------------- |
Input/Output-StreamsOpening Textfiles - ReadWe use the textfile "names.txt" which contains some names: micky mouse morty mouse minnie mouse maxi mouse monti mouse The following program reads all data from the textfile and writes it to the standard output: #include <iostream.h>
#include <fstream.h>
int main() {
char linebuffer[80];
ifstream ifs("names.txt", ios::in);
while (!ifs.eof()) {
ifs.getline(linebuffer, 80, '\n');
cout << linebuffer << endl;
}
return 0;
}
So we get the following output: micky mouse morty mouse minnie mouse maxi mouse monti mouse Creating Textfiles - Write, AppendThe following example demostrates how to append new lines to an existing textfile.
|