【初心者歓迎】C/C++室 Ver.32【環境依存OK】
■ このスレッドは過去ログ倉庫に格納されています
0778デフォルトの名無しさん
2006/11/19(日) 14:33:15工エエェェ(´ロ`ノ)ノェェエエ工
#include <cctype>
#include <cstdlib>
#include <locale>
using namespace std;
deque<string> SplitMultiByteString(const string& str) {
deque<string> words;
int len_char;
string::size_type first = string::size_type(), last, length = str.length();
locale previous = locale::global(locale("japanese", locale::ctype));
while (first < length) {
while (first < length && (len_char = mblen(&str[first], MB_CUR_MAX)) == 1 && isspace(str[first]))
first += len_char;
last = first;
while (last < length && ((len_char = mblen(&str[last], MB_CUR_MAX)) == 1 && !isspace(str[last]) || len_char > 1))
last += len_char;
if (first != last) {
words.push_back(str.substr(first, last - first));
first = last;
}
}
locale::global(previous);
return words;
}
■ このスレッドは過去ログ倉庫に格納されています