小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

用C++ STL實(shí)現(xiàn)的字符串分割

 mrjbydd 2012-06-21
#include <iostream>
02 #include <iterator>
03 #include <string>
04 #include <vector>
05   
06 using namespace std;
07   
08 vector<string> split(const string& s) {
09   
10     vector<string> ret;
11     typedef string::size_type string_size;
12     string_size i = 0;
13   
14     // invariant: we have processed characters [original value of i, i)
15     while (i != s.size()) {
16   
17         // ignore leading blanks
18         // invariant: chartacters in range [original i, current i) are all spaces
19         while (i !=s.size() && isspace(s[i]))
20             ++i;
21   
22         // find end of next word
23         string_size j = i;
24         // invariant: none of the characters in rang [original j, current j) is a space
25         while (j != s.size() && !isspace(s[j]))
26             ++j;
27   
28         // if we found some nonewithspace characters
29         if (i != j) {
30             // copy from s starting at i and taking j - i chars
31             ret.push_back(s.substr(i, j - i));
32             i = j;
33         }
34     }
35         return ret;
36 }
37   
38 int main() {
39   
40     string s;
41   
42     // read and split each line of input
43     while (getline(cin, s)) {
44         vector<string> v = split(s);
45   
46         // write eeach word in v
47         for (vector<string>::size_type i = 0; i != v.size(); ++i)
48             cout << v[i] << endl;
49     }
50   
51     system("PAUSE");
52     return 0;
53 }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多