Advertisement
enkov

Пример за работа с низове в С++

Oct 31st, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string Name;
  10.     cout << "Enter the name: ";
  11.     getline(cin, Name);
  12.  
  13.     cout << "You entered name " << Name << endl;
  14.     cout << "This name is " << Name.length() << " characters long." << endl;
  15.     Name.append(" Petrov");
  16.     cout << "Appended " << Name << endl;
  17.     cout << "New name is " << Name.length() << " characters long." << endl;
  18.  
  19.     for (int i = 0; i < Name.length(); i++)
  20.         cout << Name[i] << endl;
  21.  
  22.     string s1, s2;
  23.     s1 = "Pexar";
  24.     s2 = "Petyr";
  25.  
  26.     if (s1 < s2)
  27.         cout << s1 << " is less than " << s2 << endl;
  28.     else  
  29.         cout << s1 << " is greater or equal than " << s2 << endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement