#include <iostream>
#include <cstdio>
#include <string>
using namespace Std;
int main ()
{
String Str ("1 2 3 4 5 6 7 8");
Char ch[] = "ABCDEFGH";
String A;
String str_1 (CH);
String str_2 (str, 2, 5);
String Str_3 (CH, 5);
String Str_4 (5, ' X ');
String Str_5 (Str.begin (), Str.end ());
cout<< "Output digital sequence" <<endl;
cout<<str<<endl;
cout<< "output character sequence" <<endl;
cout<<ch<<endl;
cout<<a<<endl;
cout<<str_1<<endl;
cout<<str_2<<endl;
cout<<str_3<<endl;
cout<<str_4<<endl;
cout<<str_5<<endl;
return 0;
}
==========================================================
#include <iostream>
#include <cstdio>
#include <string>
using namespace Std;
int main ()
{
int size = 0;
int length = 0;
unsigned long maxsize = 0;
int capacity = 0;
String str ("12345678");
String Str_custom;
Pre-allocated storage size
Str_custom.reserve (5);
Str_custom = str;
To find the number of characters
Size = Str_custom.size ();
Length = Str_custom.length ();
Maximum capacity of a character
MaxSize = Str_custom.max_size ();
Maximum memory capacity that can be obtained before new memory is allocated
Capacity = Str_custom.capacity ();
cout<< "size =" <<size<<endl;
cout<< "length =" <<length<<endl;
cout<< "maxsize =" <<maxsize<<endl;
cout<< "Capacity =" <<capacity<<endl;
return 0;
}
========================================================
#include <iostream>
#include <cstdio>
#include < String>
using namespace std;
int main ()
{
string CS ("conststring");
string S ("ABCDE");
char temp = 0;
char temp_1 = 0;
char temp_2 = 0;
char temp_3 = 0;
char temp_4 = 0;
char temp_5 = 0;
temp =s[2];
temp_1 = s.at (2);
temp_2 = Cs[cs.length ()];
cout<<temp_1<<endl;
Cout<<temp_2<<endl;
return 0;
}
=========================================================
Comparison
#include <iostream>
#include <cstdio>
#include < String>
using namespace std;
int main ()
{
string A ("ABcdef");
string B ("AbcdEf");
string C ("123456");
string D ("123DFG");
int m = A.compare (B);
int n = a.compare (1, 5, B);
int p = a.compare (1, 5, B, 4, 2);
int q = C.compare (0, 3, D, 0, 3);
cout<< "m=" <<m<< "n=" <<n<< "p=" <<p << ", q=" <<q<<endl;
return 0;
}
C + + string processing