std::string用法まとめ

3085 ワード

           string ,                   。           ,        :

string      :
string(const char *s);    // c   s   string(int n,char c);     // n   c   


string      :
const char &operator[](int n)const;
const char &at(int n)const;
char &operator[](int n);
char &at(int n);
operator[] at()          n      , at        ,       out_of_range  ,     []       。
const char *data()const;//     null   c    
const char *c_str()const;//     null   c   
int copy(char *s, int n, int pos = 0) const;//      pos   n       s           ,         

 :  string        ,         CCtype    ,        


string     :
int capacity()const;    //      ( string                )
int max_size()const;    //  string               
int size()const;        //          
int length()const;       //          
bool empty()const;        //         
void resize(int len,char c);//          len,    c       

string        :string      operator>>    ,       operator<","=","<=","!="            ;
int compare(const string &s) const;//        s   
int compare(int pos, int n,const string &s)const;//        pos   n          s   
int compare(int pos, int n,const string &s,int pos2,int n2)const;//        pos   n          s pos2   n2            
int compare(const char *s) const;
int compare(int pos, int n,const char *s) const;
int compare(int pos, int n,const char *s, int pos2) const;
compare   >   1,    
  :
    string input("hello,this is a test");
    istringstream is(input);
    string s1,s2,s3,s4;
    is>>s1>>s2>>s3>>s4;//s1="hello,this",s2="is",s3="a",s4="test"
    ostringstream os;
    os<
std::string s1;
std::string s3(s2);
std::string s2("this is a string");
begin                 Iterator
end                 Iterator
rbegin                   Iterator
rend                   Iterator
size               
length()        size      
max_size                 
capacity                   ,        
empty             
operator[]             ,     
c_str         C   const char*    
data                
operator=            
reserve           
swap           
insert           
append           
push_back           
erase            
clear                  
resize             
assign               
replace         
copy             
find         ,    0    
rfind           
find_first_of                   ,       
find_first_not_of                    ,       
find_last_of                   ,        
find_last_not_of                    ,        
substr(n1,len)             n1      len   
     (          )
compare            
operator+            
operator+=       +=    
operator==             
operator!=              
operator<             
operator>>                 
operator<<               
getline