//文本查询
// 要做的事情
// 1、把一个文本 的每一行 放入 vector 中。
// 2、记录每一个单词的行号
// 3、根据行号输出每行单词。
class TextQuery
{
public:
typedef vector
void store_file( ifstream& is);
set
stringprint_linestring(line_no)const ;
private:
vector
map
};
void TextQuery::store_file(ifstream& is)
{
string word;
while ( getline( is,word ) )
{
line_of_text.push_back(word);
}
line_no num;
for( num=0; num != line_of_text.size(); ++num )
{
string line, tempword;
istringstream istream(line_of_text[num]);
while ( istream>> word)
{
word_map[word].insert(num);
}
}
}
set
{
map
if (iter == word_map.end())
{
return set
}
return iter->second;
}
string TextQuery::print_linestring(line_no num)
{
if ( num< line_of_text.size())
{
return line_of_text[num];
}
}
void print_result(const set
{
cout<<"str:"< set for (; iter != los.end();++iter) { cout<< *iter+1 < } } void main( void ) { }
下一篇:socket的一些函数分析