当前位置:首页 » 多媒体相关

运行代码!


 
  #include   <algorithm>  
  #include   <string>  
  #include   <vector>  
  #include   <utility>  
  #include   <map>  
  #include   <set>  
   
  #include   <iostream.h>  
  #include   <fstream.h>  
   
  #include   <stddef.h>  
  #include   <ctype.h>  
   
  typedef   pair<short,short>                       location;  
  typedef   vector<location,allocator>     loc;  
  typedef   vector<string,allocator>         text;  
  typedef   pair<text*,loc*>                         text_loc;  
   
  class   textquery   {  
  public:  
  textquery()   {   memset(   this,   0,   sizeof(   textquery   ));   }  
   
  static   void   filter_elements(   string   felems   )   {   filt_elems   =   felems;   }  
   
  void   query_text();  
  void   display_map_text();  
  void   display_text_locations();  
  void   doit()   {  
                  retrieve_text();  
                  separate_words();  
                  filter_text();  
                  suffix_text();  
                  strip_caps();  
                  build_word_map();  
  }  
   
  private:  
  void   retrieve_text();  
  void   separate_words();  
  void   filter_text();  
  void   strip_caps();  
  void   suffix_text();  
  void   suffix_s(   string&   );  
  void   build_word_map();  
   
  private:  
  vector<string,allocator>       *lines_of_text;  
  text_loc                                       *text_locations;  
  map<string,loc*,less<string>,allocator>   *word_map;  
  static   string   filt_elems;  
  };  
   
  string   textquery::filt_elems(   "\",.;:!?)(\\/"   );  
   
  int   main()    
  {  
  textquery   tq;  
  tq.doit();  
  tq.query_text();  
                  tq.display_map_text();  
  return   0;  
  }  
   
  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.length();  
                                  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   );  
  }  
   
  void    
  textquery::  
  filter_text()  
  {  
  if   (   filt_elems.empty()   )  
            return;  
   
  vector<string,allocator>   *words   =   text_locations->first;  
   
  vector<string,allocator>::iterator   iter   =   words->begin();  
  vector<string,allocator>::iterator   iter_end   =   words->end();  
   
  while   (   iter   !=   iter_end   )  
  {  
                                  string::size_type   pos   =   0;  
                                  while   ((   pos   =   (*iter).find_first_of(   filt_elems,   pos   ))   !=   string::npos   )  
                                                (*iter).erase(pos,1);  
  iter++;  
  }  
  }  
   
 

推荐阅读

  • 新一代源代码保护解决方案 [详细内容]
  • 手机无线搜索的代理 让您在“迷你”尽观商机 [详细内容]
  • 国产手机借力强势传媒资源 [详细内容]
  • Sun开放部分源代码 Java迎来参与时代 [详细内容]
  • 关于Mp3的一点小技巧 [详细内容]
  • 长城电脑行至人事风暴眼 周庚申新政将触发 [详细内容]
  • IBM将公开Cell处理器规格 并发布源代码 [详细内容]
  • 网友回答:
    网友:jwwu

    一编译20几个错

    网友:kuanghong

    你因改把编译的错误写出来,不是把代码拿上来。  
       
      一个最大的错误是在开头没有语句"using   namespace   std;"

    .

    讨论区

    Login