2012-04-19 7 views

答えて

2

行く方法を確認してみてください:

while ((stop=std::find(start, text.end(), ',')) != text.end()) { 
    words.push_back(std::string(start, stop)); 
    start = stop+1; 
} 
words.push_back(std::string(start, text.end())); 

編集:とし要件が少し奇妙に思えることを指摘しておかなければなりません。なぜ、std::vector<char>で始まっていますか? std::stringがより一般的になります。

+0

うん、今はうまくいきます。 – jjjojjjooo

0
vector<char> text = ...; 
list<string> words; 

ostringstream s; 

for (auto c : text) 
    if (c == ',') 
    { 
     words.push_back(s.str()); 
     s.str(""); 
    } 
    else 
     s.put(c); 

words.push_back(s.str()); 
+0

ostringstreamの使用中に不完全な型が許可されていません。 – jjjojjjooo

+0

@jjjojjooo: ''を含める必要があります。 –

0

この単純な擬似コードをコーディングし、それは私が、私はそれをこのような何かと思う

string tmp; 
for i = 0 to text.size 
    if text[i] != ',' 
     insert text[i] to tmp via push_back 
    else add tmp to words via push_back and clear out tmp 
関連する問題