he full use of the C standard library is available for use by utilizing the
".c_str" function return of the string class.
-
01#include <strings.h>02#include <string>03#include <stdio.h>04usingnamespacestd;0506intmain()07{08char*phrase1="phrase";09string phrase2("Second phrase");10charphraseA[128];11char*phraseB;1213strcpy(phraseA,phrase2.c_str());14phraseB =strstr(phrase2.c_str(),phrase1);1516printf("phraseA: %s\n",phraseA);17printf("phraseB: %s\n",phraseB);18printf("phrase2: %s\n",phrase2.c_str());19}
[prompt]$ g++ test.cpp [prompt]$ ./a.out phraseA: Second phrase phraseB: phrase phrase2: Second phrase
Tidak ada komentar:
Posting Komentar