Добрый день! Помогите пожалуйста разобраться с функцией.. (функция инициализирует карту(map) из файла, где ключем становится первое слово в строке, а остальные слова строки, становятся значениями)
| Код | / * Essential C++ -- Stanley Lippman*/ void populate_map( ifstream &nameFile, map<string,vstring> &families ) { string textline; while ( getline( nameFile, textline, '\n' )) { string fam_name; vector<string> child; cout << "textline: " << textline << endl;
string::size_type pos = 0, prev_pos = 0, /*кто такой size_type?*/ text_size = textline.size();
if ( ! text_size ) continue;
// ok: find each word separated by a space while (( pos = textline.find_first_of( ' ', pos )) != string::npos ) /*а что тут делает npos?*/ { string::size_type end_pos = pos-prev_pos; if ( ! prev_pos ) fam_name = textline.substr( prev_pos, end_pos ); else child.push_back(textline.substr(prev_pos,end_pos)); prev_pos = ++pos; } // now handle last child if ( prev_pos < text_size ) child.push_back(textline.substr(prev_pos,pos-prev_pos));
cout << "family name: " << fam_name << " children: " << child.size() << endl;
if ( ! families.count( fam_name )) families[ fam_name ] = child; else cerr << "Oops! We already have a " << fam_name << " family in our map!\n"; } }
|
заранее благодарен. |