Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Textübergabe an Datei

Empfohlene Antworten

Veröffentlicht

Hi Leute,

ich will einen char - Array in eine von mir selbst erstellte Datei einfügen. In diese Datei sollen mehrere Arrays hintereinander eingefügt werden. Die Befehle fgets, fwrite und fopen kenn ich schon, weiß aber nicht, wie ich sie richtig benutze.

Danke für eure Hilfe...

Ich schreibe das Programm in C++

??? Wie Du kennst die Funktionen, kannst sie aber nicht anwenden? Aber egal, wenn Du eh in C++ programmierst, dann solltest Du die Typen ifstream und ofstream benutzen...

Zum Beispiel:

ofstream out ("test.txt");

string txt ="hallo welt";

out << txt;

HTH

Jan

Tut mir ja sehr leid, aber ich check das nicht. Was ist da was. Erklär den Code mal bitte ein bisschen.

In seinem Code schreibt er das was in dem Array steht in die Datei! Mehr nicht.

Was für eine Programmierumgebung benutz Du?

Mit was lernst Du?

Bine

Ich benutze Visual C++ 4.0 unter Windows NT 4.0.

Hast Du eine MSDN?

Bine

Nein

Das ist schlecht!

Nun, dann gebe ich Dir hier die Information, wie man ifstream und ofstream benutzt. Ließ es Dir genau durch, und wenn Du dann noch eine kronkrete Frage hast, frag!

ifstream

ifstream

#include <fstream.h>

The ifstream class is an istream derivative specialized for disk file input. Its constructors automatically create and attach a filebuf buffer object.

The filebuf class documentation describes the get and put areas and their associated pointers. Only the get area and the get pointer are active for the ifstream class.

Construction/Destruction — Public Members

ifstream

Constructs an ifstream object.

~ifstream

Destroys an ifstream object.

Operations — Public Members

open

Opens a file and attaches it to the filebuf object and thus to the stream.

close

Closes the stream’s file.

setbuf

Associates the specified reserve area to the stream’s filebuf object.

setmode

Sets the stream’s mode to binary or text.

attach

Attaches the stream (through the filebuf object) to an open file.

Status/Information — Public Members

rdbuf

Gets the stream’s filebuf object.

fd

Returns the file descriptor associated with the stream.

is_open

Tests whether the stream’s file is open.

ofstream

#include <fstream.h>

The ofstream class is an ostream derivative specialized for disk file output. All of its constructors automatically create and associate a filebuf buffer object.

The filebuf class documentation describes the get and put areas and their associated pointers. Only the put area and the put pointer are active for the ofstream class.

Construction/Destruction — Public Members

ofstream

Constructs an ofstream object.

~ofstream

Destroys an ofstream object.

Operations — Public Members

open

Opens a file and attaches it to the filebuf object and thus to the stream.

close

Flushes any waiting output and closes the stream’s file.

setbuf

Associates the specified reserve area to the stream’s filebuf object.

setmode

Sets the stream’s mode to binary or text.

attach

Attaches the stream (through the filebuf object) to an open file.

Status/Information — Public Members

rdbuf

Gets the stream’s filebuf object.

fd

Returns the file descriptor associated with the stream.

is_open

Tests whether the stream’s file is open.

Beispiel:

char szBuffer[1000]={NULL};

int nCharacter=0;

ifstream Test("c:\Test.txt", ios::in);

ofstream TestTemp("c:\TestTemp.txt", ios::out);

do

{

nCharacter = Test.get();

TestTemp << nCharacter << "\n";

}while(nCharacter != EOF)

TestTemp.close();

Test.close();

remove("c:\Test.txt");

rename("c:\TestTemp.txt", "c:\Test.txt");

In diesem Beispiel habe ich die Datei Test.txt zum lesen geschaffen und gleichzeitig geöffnet, die Datei TestTemp.txt zum schreiben. Nun lese ich Buchstabe für Buchstabe aus der Test.txt aus, und schreibe jeden Buchstabe einzeln in die TestTemp.txt und hänge dahinter jeweils einen Zeilenumbruch.

Am Ende schließe ich die Dateien wieder, schmeiße die Test.txt weg, und nenne die TestTemp.txt in Test.txt um!

Bine

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.