1#include <iostream>2#include <string>3 4 using namespacestd;5 6 voidDisplay (Const string&str)7 {8cout<<"String:"<<str<<Endl;9cout<<"Empty:"<<str.empty () <<Endl;Tencout<<"Size:"<<str.size () <<Endl; Onecout<<"Length:"<<str.length () <<Endl; Acout<<"Capacity:"<<str.capacity () <<Endl; -cout<<"Maxsize:"<<str.max_size () <<Endl; -cout<<Endl; the } - - - int_tmain (intARGC, _tchar*argv[]) + { - strings1=""; No byte + Display (S1); A at stringS2=" "; Two empty sections - Display (S2); - - strings3="123456"; - Display (S3); - in strings4="123 456 ASD"; - Display (S4); to + /*s3.resize (+); - Display (S3);*/ the *System"Pause"); $ return 0;Panax Notoginseng}
Results
But the member function empty () is used to verify that the number of characters is 0, that is, if the string is empty, it is faster than length () or size ().
Comparison of Empty,size,length of string