1// string::length
2#include <iostream>
3#include <string>
4
5int main ()
6{
7 std::string str ("Test string");
8 std::cout << "The size of str is " << str.length() << " bytes.\n";
9 return 0;
10}
1#include <iostream>
2#include <string>
3
4int main()
5{
6 string str = "iftee";
7
8 //method 1: using length() function
9 int len = str.length();
10 cout << "The String Length: " << len << endl;
11
12 //method 2: using size() function
13 int len2 = str.size();
14 cout << "The String Length: " << len2 << endl;
15
16 return 0;
17}
1#include <string>
2#include <iostream>
3
4int main()
5{
6 std::string s(21, '*');
7
8 std::cout << s << std::endl;
9
10 return 0;
11}
12
1string str ="hello world";
2//different ways to find length of a string:
3str.length();
4str.size();
5
1#include <iostream>
2using namespace std;
3int main() {
4 string str = "Viet Nam";
5 cout << "String Length = " << str.size();
6 // you can also use str.length()
7 return 0;
8}