Tính độ dài chuỗi trong C++

    • Để tính  độ dài của một chuỗi, ta sử dụng hàm length()
    • Ví dụ:
 
#include <iostream>
using namespace std;

int main () {
string txt = "ABCD";
cout << "Do dai cua chuoi txt là: " << txt.length();
return 0;
}

– Kết quả:

– Ngoài ra, các bạn cũng có thể sử dụng hàm size() để lấy độ dài của chuỗi.
Ví dụ:

 
#include <iostream>
using namespace std;

int main () {
string txt = "ABCD";
cout << "Do dai cua chuoi txt là: " << txt.size();
return 0;
}

– Kết quả tương tự hàm length()

1 Comment

  1. I have read a feww excelent stuff here. Definitely value
    bookmarking for revisiting. I wonder how much effort you put to make
    any such fantastic informative website.

    Here is my site; Youtube

Leave a Reply

Your email address will not be published. Required fields are marked *