xxxxxxxxxx
// string::length
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
std::cout << "The size of str is " << str.length() << " bytes.\n";
return 0;
}
xxxxxxxxxx
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char ary[] = "Welcome to Softhunt.net";
cout << "Length of String = " << strlen(ary)<<endl;
return 0;
}
xxxxxxxxxx
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.length();
xxxxxxxxxx
string str ="hello world";
//different ways to find length of a string:
str.length();
str.size();
xxxxxxxxxx
#include <iostream>
using namespace std;
int main() {
string str = "Viet Nam";
cout << "String Length = " << str.size();
// you can also use str.length()
return 0;
}
xxxxxxxxxx
#include <string>
#include <iostream>
int main()
{
std::string s(21, '*');
std::cout << s << std::endl;
return 0;
}