青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

T9的空間

You will never walk alone!

  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
  69 隨筆 :: 0 文章 :: 28 評論 :: 0 Trackbacks
  1#include<iostream>
  2#include<string>
  3#include<algorithm>
  4using namespace std;
  5int main()
  6{
  7    string str1,str2;
  8    //string類的構造函數:
  9    //string(const char *s);    //用c字符串s初始化
 10    //string(int n,char c);     //用n個字符c初始化
 11    //此外,string類還支持默認構造函數和復制構造函數,如string s1;string s2="hello";都是正確的寫法。當構造的string太長而無法表達時會拋出length_error異常 
 12
 13
 14
 15    //string的賦值:
 16    //string &operator=(const string &s);//把字符串s賦給當前字符串
 17    //string &assign(const char *s);//用c類型字符串s賦值
 18    //string &assign(const char *s,int n);//用c字符串s開始的n個字符賦值
 19    //string &assign(const string &s);//把字符串s賦給當前字符串
 20    //string &assign(int n,char c);//用n個字符c賦值給當前字符串
 21    //string &assign(const string &s,int start,int n);//把字符串s中從start開始的n個字符賦給當前字符串
 22    //string &assign(const_iterator first,const_itertor last);//把first和last迭代器之間的部分賦給字符串
 23
 24    str1.assign("hell0");
 25    cout<<str1<<endl;
 26    cin>>str2;
 27    str1.assign(str2);
 28    cout<<str1<<endl;
 29
 30    string str3="word";
 31    str1.assign(str3,1,2);
 32    cout<<str1<<endl;
 33
 34    str1.assign(str3.begin()+1,str3.end());
 35    cout<<str1<<endl;
 36    //string的特性描述:
 37    //int capacity()const;    //返回當前容量(即string中不必增加內存即可存放的元素個數)
 38    //int max_size()const;    //返回string對象中可存放的最大字符串的長度
 39    //int size()const;        //返回當前字符串的大小
 40    //int length()const;       //返回當前字符串的長度
 41    //bool empty()const;        //當前字符串是否為空
 42    //void resize(int len,char c);//把字符串當前大小置為len,并用字符c填充不足的部分 
 43    cout<<str2.size ()<<" "<<str2.length()<<" "<<str2.capacity()<<endl;
 44    cout<<str2.empty()<<endl;
 45    cout<<str2.max_size()<<endl;
 46    //string類的輸入輸出操作:
 47    //string類重載運算符operator>>用于輸入,同樣重載運算符operator<<用于輸出操作。
 48    //函數getline(istream &in,string &s);用于從輸入流in中讀取字符串到s中,以換行符'\n'分開。
 49    //實際上getline可以指定結束標志
 50    getchar();
 51    
 52    string str4;
 53    getline(cin,str4,'\n');
 54    cout<<"str4:"<<str4<<endl;
 55    getchar();
 56
 57    getline(cin,str4,'a');
 58    cout<<"getline2: "<<str4<<endl;
 59
 60    //string的連接:
 61    //string &operator+=(const string &s);//把字符串s連接到當前字符串的結尾 
 62    //string &append(const char *s);            //把c類型字符串s連接到當前字符串結尾
 63    //string &append(const char *s,int n);//把c類型字符串s的前n個字符連接到當前字符串結尾
 64    //string &append(const string &s);    //同operator+=()
 65    //string &append(const string &s,int pos,int n);//把字符串s中從pos開始的n個字符連接到當前字符串的結尾
 66    //string &append(int n,char c);        //在當前字符串結尾添加n個字符c
 67    //string &append(const_iterator first,const_iterator last);//把迭代器first和last之間的部分連接到當前字符串的結尾 
 68
 69    cout<<"str2:"<<str2<<endl;
 70    str2.append(str4,0,str4.length());
 71    cout<<"str2: "<<str2<<endl;
 72    str2.append(3,'!');
 73    cout<<"str2: "<<str2<<endl;
 74    str2+=" "+str3;
 75    cout<<"str2: "<<str2<<endl;
 76
 77    //string的比較:
 78    //bool operator==(const string &s1,const string &s2)const;//比較兩個字符串是否相等
 79    //運算符">","<",">=","<=","!="均被重載用于字符串的比較;
 80    //int compare(const string &s) const;//比較當前字符串和s的大小
 81    //int compare(int pos, int n,const string &s)const;//比較當前字符串從pos開始的n個字符組成的字符串與s的大小
 82    //int compare(int pos, int n,const string &s,int pos2,int n2)const;//比較當前字符串從pos開始的n個字符組成的字符串與s中pos2開始的n2個字符組成的字符串的大小
 83    //int compare(const char *s) const;
 84    //int compare(int pos, int n,const char *s) const;
 85    //int compare(int pos, int n,const char *s, int pos2) const;
 86    //compare函數在>時返回1,<時返回-1,==時返回0 
 87    
 88    //string的子串:
 89    //string substr(int pos = 0,int n = npos) const;//返回pos開始的n個字符組成的字符串
 90
 91    str4=str2.substr(1,5);
 92    cout<<"str4: "<<str4<<endl;
 93/*  
 94    string類的查找函數: 
 95
 96    int find(char c, int pos = 0) const;//從pos開始查找字符c在當前字符串的位置
 97    int find(const char *s, int pos = 0) const;//從pos開始查找字符串s在當前串中的位置
 98    int find(const char *s, int pos, int n) const;//從pos開始查找字符串s中前n個字符在當前串中的位置
 99    int find(const string &s, int pos = 0) const;//從pos開始查找字符串s在當前串中的位置
100    //查找成功時返回所在位置,失敗返回string::npos的值 
101
102    int rfind(char c, int pos = npos) const;//從pos開始從后向前查找字符c在當前串中的位置
103    int rfind(const char *s, int pos = npos) const;
104    int rfind(const char *s, int pos, int n = npos) const;
105    int rfind(const string &s,int pos = npos) const;
106    //從pos開始從后向前查找字符串s中前n個字符組成的字符串在當前串中的位置,成功返回所在位置,失敗時返回string::npos的值 
107
108    int find_first_of(char c, int pos = 0) const;//從pos開始查找字符c第一次出現的位置
109    int find_first_of(const char *s, int pos = 0) const;
110    int find_first_of(const char *s, int pos, int n) const;
111    int find_first_of(const string &s,int pos = 0) const;
112    //從pos開始查找當前串中第一個在s的前n個字符組成的數組里的字符的位置。查找失敗返回string::npos 
113
114    int find_first_not_of(char c, int pos = 0) const;
115    int find_first_not_of(const char *s, int pos = 0) const;
116    int find_first_not_of(const char *s, int pos,int n) const;
117    int find_first_not_of(const string &s,int pos = 0) const;
118    //從當前串中查找第一個不在串s中的字符出現的位置,失敗返回string::npos 
119
120    int find_last_of(char c, int pos = npos) const;
121    int find_last_of(const char *s, int pos = npos) const;
122    int find_last_of(const char *s, int pos, int n = npos) const;
123    int find_last_of(const string &s,int pos = npos) const; 
124
125    int find_last_not_of(char c, int pos = npos) const;
126    int find_last_not_of(const char *s, int pos = npos) const;
127    int find_last_not_of(const char *s, int pos,  int n) const;
128    int find_last_not_of(const string &s,int pos = npos) const;
129    //find_last_of和find_last_not_of與find_first_of和find_first_not_of相似,只不過是從后向前查找 
130
131  
132
133    string類的替換函數: 
134
135    string &replace(int p0, int n0,const char *s);//刪除從p0開始的n0個字符,然后在p0處插入串s
136    string &replace(int p0, int n0,const char *s, int n);//刪除p0開始的n0個字符,然后在p0處插入字符串s的前n個字符
137    string &replace(int p0, int n0,const string &s);//刪除從p0開始的n0個字符,然后在p0處插入串s
138    string &replace(int p0, int n0,const string &s, int pos, int n);//刪除p0開始的n0個字符,然后在p0處插入串s中從pos開始的n個字符
139    string &replace(int p0, int n0,int n, char c);//刪除p0開始的n0個字符,然后在p0處插入n個字符c
140    string &replace(iterator first0, iterator last0,const char *s);//把[first0,last0)之間的部分替換為字符串s
141    string &replace(iterator first0, iterator last0,const char *s, int n);//把[first0,last0)之間的部分替換為s的前n個字符
142    string &replace(iterator first0, iterator last0,const string &s);//把[first0,last0)之間的部分替換為串s
143    string &replace(iterator first0, iterator last0,int n, char c);//把[first0,last0)之間的部分替換為n個字符c
144    string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last);//把[first0,last0)之間的部分替換成[first,last)之間的字符串 
145
146    string類的插入函數: 
147
148    string &insert(int p0, const char *s);
149    string &insert(int p0, const char *s, int n);
150    string &insert(int p0,const string &s);
151    string &insert(int p0,const string &s, int pos, int n);
152    //前4個函數在p0位置插入字符串s中pos開始的前n個字符
153    string &insert(int p0, int n, char c);//此函數在p0處插入n個字符c
154    iterator insert(iterator it, char c);//在it處插入字符c,返回插入后迭代器的位置
155    void insert(iterator it, const_iterator first, const_iterator last);//在it處插入[first,last)之間的字符
156    void insert(iterator it, int n, char c);//在it處插入n個字符c
157  
158
159    string類的刪除函數 
160
161    iterator erase(iterator first, iterator last);//刪除[first,last)之間的所有字符,返回刪除后迭代器的位置
162    iterator erase(iterator it);//刪除it指向的字符,返回刪除后迭代器的位置
163    string &erase(int pos = 0, int n = npos);//刪除pos開始的n個字符,返回修改后的字符串 
164
165  
166
167    string類的迭代器處理: 
168
169    string類提供了向前和向后遍歷的迭代器iterator,迭代器提供了訪問各個字符的語法,類似于指針操作,迭代器不檢查范圍。
170    用string::iterator或string::const_iterator聲明迭代器變量,const_iterator不允許改變迭代的內容。常用迭代器函數有:
171    const_iterator begin()const;
172    iterator begin();                //返回string的起始位置
173    const_iterator end()const;
174    iterator end();                    //返回string的最后一個字符后面的位置
175    const_iterator rbegin()const;
176    iterator rbegin();                //返回string的最后一個字符的位置
177    const_iterator rend()const;
178    iterator rend();                    //返回string第一個字符位置的前面
179    rbegin和rend用于從后向前的迭代訪問,通過設置迭代器string::reverse_iterator,string::const_reverse_iterator實現 
180
181  
182
183    字符串流處理: 
184
185    通過定義ostringstream和istringstream變量實現,<sstream>頭文件中
186    例如:
187        string input("hello,this is a test");
188        istringstream is(input);
189        string s1,s2,s3,s4;
190        is>>s1>>s2>>s3>>s4;//s1="hello,this",s2="is",s3="a",s4="test"
191        ostringstream os;
192        os<<s1<<s2<<s3<<s4;
193        cout<<os.str(); 
194*/

195    return 0;
196}
posted on 2008-08-19 17:16 Torres 閱讀(282) 評論(0)  編輯 收藏 引用
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            91久久中文| 亚洲欧洲日夜超级视频| 亚洲全黄一级网站| 一区二区三区高清在线| 久久九九99| 国产精品久久久久9999| 亚洲二区在线观看| 欧美一区二区三区在| 亚洲人精品午夜| 国产精品久久久一本精品| 99这里只有久久精品视频| 免费成人av| 欧美在线视频在线播放完整版免费观看| 欧美激情中文字幕一区二区| 激情视频一区二区| 久久精品99久久香蕉国产色戒 | 在线观看福利一区| 午夜精品亚洲| 在线视频精品| 欧美吻胸吃奶大尺度电影| 99av国产精品欲麻豆| 欧美成人一区在线| 久久美女性网| 在线欧美日韩国产| 欧美mv日韩mv国产网站| 久久久亚洲成人| 1000部精品久久久久久久久| 亚洲免费高清| 欧美四级在线| 亚洲欧美日韩国产成人精品影院| 99视频一区| 国产精品一区二区三区久久| 欧美一区二区三区在线| 牛牛精品成人免费视频| 99re热这里只有精品视频| 午夜精品一区二区在线观看| 国语自产精品视频在线看抢先版结局| 久久激情网站| 国产精品看片资源| 亚洲黄色av| 99精品福利视频| 这里只有精品电影| 91久久精品www人人做人人爽| 亚洲影院免费| 精品96久久久久久中文字幕无| 亚洲精品免费一二三区| 在线精品一区| 久久久久成人精品免费播放动漫| 亚洲一区二区三区精品在线| 亚洲欧美视频| 亚洲国产小视频| 亚洲巨乳在线| 国产日本欧洲亚洲| 欧美高清在线精品一区| 国产综合色产在线精品| 亚洲国产精品第一区二区三区 | 欧美一区二区三区视频免费播放 | 久久精品国产99| 亚洲国产婷婷香蕉久久久久久99| 欧美一区2区三区4区公司二百| 亚洲永久免费观看| 狂野欧美性猛交xxxx巴西| 亚洲香蕉视频| 欧美日韩小视频| 久热re这里精品视频在线6| 欧美理论在线播放| 久久精品综合| 欧美啪啪一区| 9久re热视频在线精品| 亚洲一区国产| 国产精品久久久久久久久免费樱桃 | 99精品国产高清一区二区| 亚洲少妇在线| 久久青青草综合| 欧美 日韩 国产在线| 亚洲人成网站精品片在线观看| 久久蜜桃资源一区二区老牛| 欧美激情一区二区三区不卡| 国产麻豆午夜三级精品| 小黄鸭精品aⅴ导航网站入口| 久久精品色图| 亚洲国产精品久久91精品| 欧美金8天国| 亚洲欧洲一区| 欧美一区二区成人| 亚洲成人在线免费| 欧美日韩日日骚| 性色av一区二区三区红粉影视| 久色成人在线| 亚洲午夜三级在线| 精品动漫3d一区二区三区免费| 免费在线视频一区| 亚洲午夜一区二区| 亚洲欧美日韩一区| 在线观看成人小视频| 欧美日韩一区二| 久久精品99无色码中文字幕| 亚洲国产成人一区| 亚洲国产综合在线| 国产精品极品美女粉嫩高清在线| 久久9热精品视频| 亚洲乱码久久| 农村妇女精品| 欧美一区日韩一区| 日韩网站免费观看| 黄色成人在线| 国产伦精品一区二区三区视频孕妇 | 亚洲天堂av高清| 欧美高清在线视频观看不卡| 午夜欧美精品久久久久久久| 亚洲国产欧美一区二区三区丁香婷| 欧美亚日韩国产aⅴ精品中极品| 久久天天狠狠| 午夜亚洲影视| 亚洲少妇自拍| 亚洲精品少妇网址| 欧美va天堂| 久久久精品视频成人| 亚洲欧美影院| 亚洲天堂男人| 99热这里只有成人精品国产| 国产亚洲综合精品| 鲁鲁狠狠狠7777一区二区| 亚洲国产高潮在线观看| 久久久久久久综合| 亚洲欧美一区二区原创| 中文在线资源观看视频网站免费不卡| 在线观看日产精品| 在线成人免费观看| 国产中文一区| 国产一区二区三区在线观看视频| 欧美午夜性色大片在线观看| 欧美激情精品久久久久久变态| 中文日韩欧美| 一级日韩一区在线观看| 日韩亚洲欧美成人| 日韩视频三区| 一本色道久久综合精品竹菊| 亚洲精品影视在线观看| 亚洲精品一区二区网址| 亚洲国产岛国毛片在线| 亚洲电影自拍| 亚洲人屁股眼子交8| 亚洲精品欧美极品| 一本色道久久综合狠狠躁的推荐| 亚洲国产欧美国产综合一区| 亚洲国产另类久久精品| 亚洲人成亚洲人成在线观看| 亚洲精品欧美日韩专区| 日韩亚洲在线观看| 亚洲视频国产视频| 性色av一区二区三区在线观看| 羞羞漫画18久久大片| 久久av一区二区三区| 老司机午夜精品视频| 欧美激情视频在线播放| 国产精品hd| 黑人一区二区| 亚洲欧洲日韩在线| 亚洲尤物在线视频观看| 久久国产精品毛片| 欧美成人自拍| 一本大道久久精品懂色aⅴ| 亚洲一区二区三区涩| 久久久久成人精品| 欧美人体xx| 国产亚洲人成a一在线v站 | 欧美伦理影院| 国产婷婷97碰碰久久人人蜜臀| 欧美日韩中文字幕精品| 国产毛片一区| 亚洲高清资源| 亚洲欧美日韩成人| 欧美v国产在线一区二区三区| 亚洲精品视频免费在线观看| 亚洲欧美在线免费| 欧美黑人一区二区三区| 国产欧美成人| 亚洲乱码久久| 99在线|亚洲一区二区| 欧美在线在线| 久久久亚洲一区| 久久久久国产精品午夜一区| 亚洲第一区在线观看| 亚洲一区二区三区精品视频| 老色鬼久久亚洲一区二区| 欧美午夜一区| 亚洲人成人99网站| 久久精品女人| 夜夜嗨av一区二区三区四季av| 久久精品综合网| 国产农村妇女毛片精品久久麻豆| 亚洲第一精品电影| 久久精品九九| 亚洲午夜精品久久久久久app| 欧美91精品| …久久精品99久久香蕉国产| 久久精品国产成人| 亚洲一区二区三区免费观看 | 欧美日产国产成人免费图片|