Programmieren - alles kontrollieren 4.940 Themen, 20.676 Beiträge

Konvertierung eines stings in eine char-Variable in C++

xsyllo / 1 Antworten / Baumansicht Nickles

Hallo Leute,


ich bin auf ein Problem in C++ gestoßen wo ich nicht weiter weiß.Es handelt sich um die Umwandlung einer string-Variablen in eine char-Variable,die ich dann in vorgefertigte Funktionen,wie z.B. mkdir()


, wo es nicht möglich ist strings zu verwenden, weiterverwenden kann. Vielleicht gibt es da auch schon Funktionen die dies bewerkstelligen.Wenn ja, könntet ihr mir vielleicht die Syntax und ein Bsp. dazu geben...


´Vielleicht habt ihr auch eine andere Idee!


Danke!!!!

bei Antwort benachrichtigen
mr.escape xsyllo „Konvertierung eines stings in eine char-Variable in C++“
Optionen

M$ meint dazu folgendes:

void main( )
{
  using namespace std;

  string wort1 ( "Hallo Welt" );
  cout       cout    Â
  // Converting a string to an array of characters
  const char *ptr1 = 0;
  ptr1= wort1.data ( );
  cout       cout    Â
  // Converting a string to a C-style string
  const char *c_str1 = wort1.c_str ( );
  cout       cout     }


Und das kommt dabei raus:
The original string object wort1 is: Hallo Welt
The length of the string object wort1 = 11

The modified string object ptr1 is: Hallo Welt
The length of character array wort1 = 11

The C-style string c_str1 is: Hallo Welt
The length of C-style string wort1 = 11

mr.escape
"The man who trades freedom for security does not deserve nor will he ever receive either." - Benjamin Franklin"Wer seine Freiheit aufgibt, um Sicherheit zu erreichen, wird beides verlieren." - Georg Christoph Lichtenberg
bei Antwort benachrichtigen