Ñ++ äëÿ íà÷èíàþùèõ


         

please enter file name:


    static string                 filt_elems;

};

string TextQuery::filt_elems( "\", •;: !?)(\V" );

int main()

{

    TextQuery tq;

    tq.doit();

    tq.query_text();

    tq.display_map_text();

}

void

TextQuery::

retrieve_text()

{

    string file_name;

    cout << " please enter file name: ";

    cin >> file_name;

    ifstream infile( file_name.c_str(), ios::in );

    if ( !infile ) {

        cerr << "oops' unable to open file "

             << file_name <<    " -- bailing out!\n";

        exit( -1 );

    }

    else cout << "\n";

    lines_of_text = new vector<string,allocator>;

    string textline;

    while ( getline( infile, textline, '\n' ))

        lines_of_text->push_back( textline );

}

void

TextQuery::

separate_words()

{

    vector<string,allocator> *words =

               new vector<string,allocator>;

    vector<location,allocator> *locations =

               new vector<location,allocator>;

    for ( short line_pos = 0; line_pos < lines_of_text->size();

        line_pos++ )

    {

        short word_pos = 0;

        string textline = (*lines_of_text)[ line_pos ];

        string::size_type eol = textline.1ength();

        string::size_type pos = 0, prev_pos = 0;

        while (( pos = textline.find_first_of( ' ', pos ))

                    != string::npos )

        {

            words->push_back(

                textline.substr( prev_pos, pos - prev_pos ));

            locations->push_back(

                make_pair( line_pos, word_pos ));

            word_pos++; pos++; prev_pos = pos;

        }

        words->push_back(

            textline.substr( prev_pos, pos - prev_pos ));

        locations->push_back(make_pair(line_pos,word_pos));

    }

    text_locations = new text_loc( words, locations );


Ñîäåðæàíèå  Íàçàä  Âïåðåä