Share strcmp c++

lyan2005

New member
## STRCMP C ++
## So sánh chuỗi
## C ++ chuỗi
## C ++ strcmp
## strcmp

** strcmp trong c ++ **

Hàm `strcmp ()` so sánh hai chuỗi từ vựng.Nó trả về một số nguyên nhỏ hơn, bằng hoặc lớn hơn 0 nếu chuỗi thứ nhất nhỏ hơn, bằng hoặc lớn hơn chuỗi thứ hai, tương ứng.

Hàm `strcmp ()` có hai đối số chuỗi, `s1` và` s2` và so sánh chúng bằng ký tự.Việc so sánh là nhạy cảm trường hợp, do đó, `" A "` được coi là nhỏ hơn `" A "`.

Hàm `strcmp ()` được khai báo trong tệp tiêu đề `<cString>`.

`` `C ++
int strcmp (const char *s1, const char *s2);
`` `

**Ví dụ**

Mã sau so sánh hai chuỗi và in kết quả:

`` `C ++
#include <Istream>
#include <Cstring>

int main () {
const char *s1 = "xin chào";
const char *s2 = "thế giới";

int result = strcmp (s1, s2);

if (result <0) {
std :: cout << "S1 nhỏ hơn S2" << std :: endl;
} khác if (result == 0) {
std :: cout << "S1 bằng s2" << std = "endl;
} khác {
std :: cout << "S1 lớn hơn S2" << std :: endl;
}

trả lại 0;
}
`` `

** Đầu ra **

`` `
S1 nhỏ hơn S2
`` `

** hashtags **

* #C ++
* #dây
* #Comparison
* #lexicographical
* #strcmp
=======================================
## Strcmp C++
## String Comparison
## C++ Strings
## C++ strcmp
## strcmp

**Strcmp in C++**

The `strcmp()` function compares two strings lexicographically. It returns an integer less than, equal to, or greater than zero if the first string is less than, equal to, or greater than the second string, respectively.

The `strcmp()` function takes two string arguments, `s1` and `s2`, and compares them character by character. The comparison is case-sensitive, so `"A"` is considered to be less than `"a"`.

The `strcmp()` function is declared in the `<cstring>` header file.

```c++
int strcmp(const char *s1, const char *s2);
```

**Example**

The following code compares two strings and prints the result:

```c++
#include <iostream>
#include <cstring>

int main() {
const char *s1 = "Hello";
const char *s2 = "World";

int result = strcmp(s1, s2);

if (result < 0) {
std::cout << "s1 is less than s2" << std::endl;
} else if (result == 0) {
std::cout << "s1 is equal to s2" << std="endl;
} else {
std::cout << "s1 is greater than s2" << std::endl;
}

return 0;
}
```

**Output**

```
s1 is less than s2
```

**Hashtags**

* #C++
* #strings
* #Comparison
* #lexicographical
* #strcmp
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top