Advertisement
fcamuso

Corso Recupero - 8 Stringhe

Jul 1st, 2021
1,396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <exception>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string cognome = "";
  9.  
  10. //    cout << "Inserire un cognome: ";
  11. //    cin >> cognome;
  12.  
  13.     string copia = cognome;
  14.  
  15.     if (copia == cognome)
  16.     {
  17.       cout << "Le due stringhe sono uguali\n";
  18.     }
  19.  
  20.     string copia2 = "FERRARI";
  21.  
  22.     if (copia2 == cognome)
  23.     {
  24.       cout << "Le due stringhe sono ancora uguali\n";
  25.     }
  26.  
  27.     string s1="mare", s2="Mare";
  28.  
  29.     if (s1<s2)
  30.     {
  31.       cout << "s1 minore di s2\n";
  32.     }
  33.     else
  34.     {
  35.      if (s1>s2)
  36.      {
  37.        cout << "s1 maggiore di s2\n";
  38.      }
  39.      else
  40.      {
  41.        cout << "s1 e a2 sono uguali\n";
  42.      }
  43.     }
  44.  
  45.     string s3 = s1 + " e " + s2;
  46.     cout << s3 << endl;
  47.  
  48.     cout << s2[0] << s2[2] << endl;
  49.     cout << s2.length() << endl;
  50.     cout << s2[s2.length()-1] << endl;;
  51.  
  52.     s2[0]='m';
  53.     cout << s2 << endl;
  54.  
  55.     char c1 = ' ';
  56.     char c2 = c1;
  57.     c2 = 'Z';
  58.  
  59.     //da stringa a numeri
  60.     string s="457";
  61.     int n = stoi(s);
  62.  
  63.     s = "-678.79";
  64.     double x = stod(s);
  65.  
  66.  
  67.     //da numeri a stringa
  68.     s = to_string(n);
  69.     s = to_string(x);
  70.  
  71.  
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement