gha890826

5/6課輔-字串比較

May 13th, 2020 (edited)
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. //字串比較
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string s1="this is s1",s2="this is s2";
  9.     char c3[]="this is s1";
  10.     if(s1==s2)
  11.         cout<<"s1==s2\n";
  12.     else
  13.         cout<<"s1!=s2\n";
  14.        
  15.     if(s1==c3)
  16.         cout<<"s1==c3\n";
  17.     else
  18.         cout<<"s1!=c3\n";
  19.        
  20.     if(s1.compare(s2)==0)
  21.         cout<<"s1==s2\n";
  22.     else
  23.         cout<<"s1!=s2\n";
  24.        
  25.     return 0;
  26. }
Add Comment
Please, Sign In to add comment