Informationen zur Klasse Strings
// Name: Strings1.cpp // Inhalt: Arbeiten mit der Klasse Strings // --------------------------------------------------------------------- #include <iostream> #include <string> using namespace std; int main() {int len,pos; string s1="123"; // String s1 wird über die Klasse string definiert char s2[20]="456"; // String s2 wird als Array von char definiert cout << s1 << s2 << endl; len = s1.length(); // liefert 3, die Laenge des Strings cout << len << endl; s1.insert(2, "xy"); // s ist nun "12xy3" cout << s1 << endl; s1.erase(2,2); // s ist nun "123" cout << s1 << endl; pos = s1.find("23"); // liefert die Position 1 cout << pos << endl; fflush(stdin); getchar(); // nur wegen Windowsumgebung return 0; }