Share c++ chuỗi,

tranngocsusan1

New member
#C ++, #String, #Programming, #tutorial, #CplusPlus ## C ++ String: A Hạt hướng

Một chuỗi là một chuỗi các ký tự.Trong C ++, các chuỗi được biểu thị bằng lớp `std :: String`.Lớp `std :: String` cung cấp một số phương thức để thao tác các chuỗi, chẳng hạn như:

* `size ()`: Trả về số lượng ký tự trong chuỗi.
* `at ()`: Trả về ký tự tại chỉ mục được chỉ định.
* `append ()`: nối một chuỗi vào cuối chuỗi hiện tại.
* `Chèn ()`: Chèn một chuỗi tại chỉ mục được chỉ định.
* `Erase ()`: Xóa một chuỗi con khỏi chuỗi.

Dưới đây là một ví dụ đơn giản về cách sử dụng lớp `std :: String`:

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

int main () {
// Tạo một chuỗi.
std :: String str = "Hello World!";

// In chiều dài của chuỗi.
std :: cout << "Độ dài của chuỗi là:" << str.size () << std :: endl;

// Nhận ký tự ở chỉ mục đầu tiên.
std :: cout << "ký tự ở chỉ mục đầu tiên là:" << str.at (0) << std :: endl;

// nối một chuỗi vào cuối chuỗi hiện tại.
str.append ("Tạm biệt!");

// In chuỗi mới.
std :: cout << "Chuỗi mới là:" << str << std :: endl;

trả lại 0;
}
`` `

## Đọc thêm

* [Hướng dẫn chuỗi C ++] (C++ Strings)
* [Ngôn ngữ lập trình C ++, Phiên bản thứ tư] (Search)
* [Tham khảo chuỗi C ++] (Strings library - cppreference.com)
=======================================
#C++, #String, #Programming, #tutorial, #CplusPlus ## C++ String: A Tutorial

A string is a sequence of characters. In C++, strings are represented by the `std::string` class. The `std::string` class provides a number of methods for manipulating strings, such as:

* `size()`: Returns the number of characters in the string.
* `at()`: Returns the character at the specified index.
* `append()`: Appends a string to the end of the current string.
* `insert()`: Inserts a string at the specified index.
* `erase()`: Erases a substring from the string.

Here is a simple example of how to use the `std::string` class:

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

int main() {
// Create a string.
std::string str = "Hello world!";

// Print the length of the string.
std::cout << "The length of the string is: " << str.size() << std::endl;

// Get the character at the first index.
std::cout << "The character at the first index is: " << str.at(0) << std::endl;

// Append a string to the end of the current string.
str.append(" Goodbye!");

// Print the new string.
std::cout << "The new string is: " << str << std::endl;

return 0;
}
```

## Further Reading

* [C++ Strings Tutorial](https://www.tutorialspoint.com/cplusplus/cpp_strings.htm)
* [The C++ Programming Language, Fourth Edition](https://www.pearson.com/us/higher-education/product/The-C-Programming-Language-Fourth-Edition/9780134477425.html)
* [C++ Strings Reference](https://en.cppreference.com/w/cpp/string)
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top