7302人加入学习
(18人评价)
C++编程系列 第一季编程基础

制作于2018年2月7日

价格 免费

判断字符串数组

用 strcmp 判断数组 零相等, 非零不相等

[展开全文]

a+=b  a=a+b

 

strcmp(字符串1,字符串2)

比较字符串里的字符

0相等  非零 不等

 

string 字符串1="asd";

string 字符串2="asd";

(字符串1==字符串2)

string类型的字符串可以直接比较

[展开全文]

用strcmp来判断两个char风格字符串中字符内容是否相同,返回0则相同。直接比较时比较的是其指针(地址)

 

string风格字符串可直接比较内容是否相同,返回1则相同

[展开全文]

#include <iostream>

using namespace std;

 

int main()

{

// + - * / %

// += -= *= /= %=

//int a = 23, b = 29;

//a += b; // a = a + b;

//cout << a << endl; // 52

//a -= b;

//cout << a << endl; // 23

//a *= b;

//cout << a << endl; //667

//a /= b;

//cout << a << endl; // 23

//a %= b;

//cout << a << endl; // 23

 

// > >= < <= == !=

//bool res = 34 > 89;

//cout << res << endl; // 0

//int a = 100, b = 90;

//cout << (a > b) << endl; // 1

 

//char str1[] = "sikiedu";//"sikiedu2",则1

//char str2[] = "sikiedu";

//cout << (str1 == str2) << endl; // 0 // 笔记:判断的地址

 

////strcmp(str1, str2); // 0 相等;非0 不等

//cout << strcmp(str1, str2) << endl;

 

string str1 = "sikiedu";

string str2 = "sikiedu";

cout << (str1 == str2) << endl; // 1

 

return 0;

}

 

[展开全文]

c语言字符串数组

char 数组【】=“   ”;

c++字符串

string 变量=“   ”;

[展开全文]
  1. 对于C语言风格字符串的比较 要用 strcmp()函数比较
  2. 对于string字符串 
[展开全文]