Answer:
To check the length of a string in C++, you can use the length() or size() method of the string class. Here's an example:
Step-by-step explanation:
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "Hello, world!";
// using length()
int len = str.length();
cout << "Length of string using length() method is " << len << endl;
// using size()
int size = str.size();
cout << "Length of string using size() method is " << size << endl;
return 0;
}
In this example, we create a string str with the value "Hello, world!" and use the length() and size() methods to get the length of the string. Both length() and size() return the number of characters in the string, so they will give the same result. We store the length of the string in the variables len and size and then print them out using cout. The output will be:
Length of string using length() method is 13
Length of string using size() method is 13
Aɳʂɯҽɾҽԃ Ⴆყ ɠσԃKEY ꦿ