24.07.2007, 03:15
общий
это ответ
Здравствуйте, Losaped!
У строк из STL нет специальных функций для рапарсивания. Поэтому нужно пользоваться функциями поиска и подстрок. В приложении есть подобный пример. А для серьезных целей лучше воспользоваться классом tokenizer из библиотеки boost. Подробней об этом классе смотрите здесь:
<a href=http://www.boost.org/libs/tokenizer/index.html>http://www.boost.org/libs/tokenizer/index.html</a>
Приложение:
#include <vector>#include <string>#include <iostream>using namespace std;int main(int argc, char* argv[]) { string tokens = " .,:;@#\t\n"; string str = "This is a test string"; string::size_type beg_index = 0; string::size_type end_index = 0; vector<string> words; while((beg_index = str.find_first_not_of(tokens, end_index)) != string::npos) { end_index = str.find_first_of(tokens, beg_index); words.push_back(str.substr(beg_index, end_index - beg_index)); } vector<string>::iterator iter; for(iter = words.begin(); iter != words.end(); ++iter) cout << *iter << endl; return 0;}