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 schreibe gerade zur Übung eine eigene String-Klasse. Es funktioniert soweit alles ganz gut, aber mit dem überladenen >>-Operator hab ich ein Problem. Ich poste einfach mal den Code, vielleicht fällt euch ja auf, was ich falsch gemacht hab:

friend istream& operator>>(istream& _in, MyString& s)

{

_in >> s.string;

return _in;

}

("string" ist eine private char*-Variable der Klasse MyString). Es lässt sich kompilieren, erzeugt aber zur Laufzeit ein Speicherzugriffsproblem, nämlich: "Die Anweisung in "0x0040..." verweist auf den Speicher in "0x0042...". Der Vorgang "written" konnte nicht auf dem Speicher durchgeführt werden"

Die Begrenzung auf 100 Zeichen ist willkürlich. Ich würde folgendes empfehlen:

friend istream& operator>>(istream& _in, MyString& s)
{
delete s.string;
s.string = NULL;

std::string temp;
_in >> temp;

int len = temp.size();
if( len ) {
s.string = new char[len+1];
strcpy( s.string, temp.c_str() );
}
return _in;
}[/CODE]

Ok, hat mir weitergeholfen. Danke euch beiden.

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.