getline( cin, s1); // Read the first getline( cin, s2); // and second line. if( line1 == line2) cout << " Satrlar bir xil" << endl; else cout<<"Ular br xil emas"; return 0; } #include #include #include using namespace std; int main(){ string s1, s2; getline( cin, s1); // Read the first getline( cin, s2); // and second line. s1>s2?cout< return 0; } Solishtirish natijalari
Solishtirish natijalari bool mantiqiy tipi orqali amalga oshiriladi. s1 va s2 satrlari uchun:
s1 == s2 TRUE bo’ladi agar har ikkalasini qiymati bir hilda bo’lsa (satr uzunligi bir hil bo’lishi lozim).
s1 < s2 TRUE bo’ladi agarda s1 ning simvoli uzunligi, s2 ning simvoli uzunligidan farq qilsa. Қатор қўшиш ва олиб ташлаш INSERTING AND ERASING IN STRINGS Inserting a string string s1("Miss Summer"); s1.insert(5, "Ashley "); // Insert at position: 5 cout< string s("The summer-time"); s.erase(4,7); // Start position: 4, Quantity: 7 cout< string s("winter-story"); string s("winter-story"); s.erase(6); // s now contains "winter" cout< berilsa satr to’liq o’chiriladi Қатор ўрнини эгаллаш ва қатор қидируви. SEARCHING AND REPLACING IN STRINGS string s1("There they go again!"), s2("Bob and Bill"); s1.replace(6, 4, s2); cout<
s1.replace(6, 4, s2);
string s1("Here comes Mike!"), string s1("Here comes Mike!"), s2("my love?"); s1.replace(11, 4, s2, 0, 7); cout<
s1.replace(11, 4, s2, 0, 7);
Do'stlaringiz bilan baham: |