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

Hi!

Wie wandele ich am schlauesten ein char-array in ein Objekt vom Typ string und umgekehrt?

Hi,

was fillst du denn für nen String? Cstring std::string AnsiString(Borland Builder)?? Musst scho a weng genauer werden. Bei std::string denn du wahrscheinlich meinst würd ichs so versuchen:

std::string test1;

char testArrray[30];

strcpy(test1.c_str(), testArray);

Erklärung:

strcpy kopiert dir den 2 parameter in den 1.

Da strcpy allerdings normalerweise char * benötigt ist es nötig bei test1 noch die Funktion c_str() aufzurufen welche dies erledigt.

ich kenne nur den std::string, den meinte ich!

std::string hat einen Konstruktor für char* und einen überladenen Zuweisungsoperator, d.h.

char* pszBla = "bla";

std::string s( pszBla );

oder

char* pszBla = "bla";

std::string s = pszBla;

funktioniert.

Andersrum hat std::string die Funktion c_str(), die einen char* zurückgibt:

printf( s.c_str() );

OK! Funktioniert alles! Danke euch zwei!!! :):):)

<STRONG> <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Zitat:</font><HR>

strcpy(test1.c_str(), testArray);

</STRONG>

mmmh...ihr habt wohl recht! Ich hatte schon bessere Ideen die ist mer halt so spontan eingefallen! Bin erst gar net auf die Idee gekommen das des probleme mit der Speicherreservierung geben könnte....

Naja ich bin halt leider immer("vielleicht wirds irgendwann mal besser") noch a typischer "TRY and ERROR" programmierer ;)

Gott sei dank gibs leute die mer dann wenigstens mal in kopf waschen und sagen wies besser wär! :D

Thx!

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.