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.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich brauche von einer Datei die Größe. Mein aktueller Code sieht so aus.


FILE* fp;

if ((fp = fopen(filename.c_str(), "rb")) == NULL)

{

	// page not found

	prtdbg("file %s not found", filename.c_str());

	return false;

}

else

{

	prtdbg("file %s opened", filename.c_str());


	int size = 0;

	int ch = 0; 

	while (1) {

		ch = getc (fp);

		if (feof(fp)) {

			rewind(fp);

			break;

		} 

		size ++;

	}

// ...	

Das ganze gefällt mir aber noch nicht so richtig. Also habe ich nach einer Alternative gesucht und bin zu folgendem gelangt.

std::ifstream fp(filename.c_str(), std::ios_base::in | std::ios_base::binary);

if (fp.is_open())

{

	prtdbg("file %s was opened", filename.c_str());


	std::filebuf* pbuf = fp.rdbuf();

	long size = pbuf->pubseekoff(0, std::ios::end, std::ios_base::in | std::ios_base::binary);

	pbuf->pubseekpos(0, std::ios::in);

// ...

jeweils in size sollte nach der Abarbeitung die Dateigröße stehen. Mein Problem ist nun aber, dass das ganze nur ab und zu funktioniert. Also wie bekomme ich auf etwas eleganterem Wege wie im ersten Beispiel die Dateigröße immer richtig.

HFILE OpenFile(

LPCSTR lpFileName, // pointer to filename

LPOFSTRUCT lpReOpenBuff, // pointer to buffer for file information

UINT uStyle // action and attributes

);

The GetFileSize function retrieves the size, in bytes, of the specified file.

DWORD GetFileSize(

HANDLE hFile, // handle of file to get size of

LPDWORD lpFileSizeHigh // address of high-order word for file size

);

Und schon hast Du deine Size unter C++ ;-)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.