string :
srting (); // string
string (const *char); //
//
string (const *char, int n); // string
// n ,
//
string (string &); // ,
// ,
string :
string & operator = (const string & str);
string & operator = (const char * s);
string & operator = (char c);
string s1;
string s2 ();
string s3 (s2);
s1 = x;
s2 = s3;
.
= | |
+ | |
= = | |
! = | |
< | |
< = | |
> | |
> = | |
[ ] | |
<< | |
>> | |
+ = |
string , , .. &s[0] s.
at:
string s();
cout << s.at (1); //
assign:
assign (const string & str);
assign (const string & str, size_type pos, size_type n);
assign (const char * str, size_type n);
str ( ):
string s1 (), s2;
s2.assign (s1);
str, pos. pos , out_of_range. n , pos str, str.
n s .
append:
append (const string & str);
append (const string & str, size_type pos, size_type n);
append (const char* s, size_type n);
str ( +).
str, pos.
n s .
insert:
insert (size_type pos1, const string & str);
insert (size_type pos1, const string & str, size_type pos2, size_type n);
insert (size_type pos, const char* s, size_type n);
str , pos1 (.. str, pos1, str ).
|
|
, pos1, str n , pos2.
n , pos .
erase:
erase (size_type pos = 0, size_type n = pos);
n , pos. pos , .
clear:
void clear ();
replace:
replace (size_type pos1, size_type n1,const string & str);
replace (size_type pos1, size_type n1,const string & str, size_type pos2, size_type n2);
pos1 , ; n1 , pos2 str, ; n2 str.
:
replace (size_type pos1, size_type n1,const char* s, size_type n2);
n1 n2 s.
swap:
swap (string & s);
substr:
substr (size_type pos = 0, size_type n = npos);
n , npos.
string c_str:
const char* c_str () const;
- .
String s1 ( ), s2 (), s3();
cout << s3.insert (4, s2) << endl; // :
cout << s3.insert (7, ) << endl; // :
s1.erase (0,3); // : s1=
cout << s1.erase (12, 2) << endl; // :
string . :
size_type find (const string & str, size_type pos = 0) const;
str , pos, npos ( size_type), .
size_type find (const char , size_type pos = 0) const;
c , pos, npos, .
size_type rfind (const string & str, size_type pos = npos) const;
str pos npos, .
size_type rfind (const char c, size_type pos = 0) const;
c , pos npos, .
int i, j;
string s1 ( ), s2 ();
i = s1.find (s2);
j = s1.rfind (s2);
|
|
cout << S2 S1 << i<< endl;
cout << S2 S1 << j<< endl;
:
S2 S1 0
S2 S1 11
compare ( ):
int compare (const string & str) const;
int compare (size_type pos1, size_type n1, const string & str) const;
int compare (size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const;
, str, , , , . (), .. aa aa , ..
, str n1 , pos1.
n1 , pos1, str n2 , pos2.