当前位置: 首页>>代码示例>>C++>>正文


C++ WordList::read方法代码示例

本文整理汇总了C++中WordList::read方法的典型用法代码示例。如果您正苦于以下问题:C++ WordList::read方法的具体用法?C++ WordList::read怎么用?C++ WordList::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WordList的用法示例。


在下文中一共展示了WordList::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: merge_file

//********************************************************
void WordsEdit::merge_file()
{

  WordList w = WordList();
  Q3FileDialog *f = new Q3FileDialog(0,"Open",true);  
  const char *filters[] = {"words.tok","*.tok","All files (*)",NULL};
  
  f->setFilters(filters);
  f->setCaption("Open");
  f->setMode(Q3FileDialog::ExistingFile);
  f->setDir(game->dir.c_str());
  if ( f->exec() == QDialog::Accepted ) {
    if ( !f->selectedFile().isEmpty() ){
      int ret = w.read((char *)f->selectedFile().latin1());
      if(ret)return ;
      wordlist->merge(w);
      update_all();
    }
  }
  
}
开发者ID:saintfrater,项目名称:qt-agi-studio,代码行数:22,代码来源:wordsedit.cpp

示例2: main

int main(int argc, char *argv[])
{
    ofstream log; // to record log file
    log.open("log.txt", std::fstream::app);
    CommandLineParser clp(argv[1],',');   //instantiating the class CommandLineParser

    if (argc == 1) 
    {
        log << "Error: no argument is passed.\n" << endl;
        log.close();
        return -1;
    }

    //use CommandLineParser to get the script name
    char *script = clp.extract("script");
    if (script == NULL || *script == '\0')
    {
        log << "Error: no script file specified.\n" << endl;
        log.close();
        return -1;
    }
    
    //use ScriptParser to get the commands from script file
    ScriptParser SParser = ScriptParser();
    ifstream indata(script);
    if (!indata.is_open()) // check if script file is correctly opened.
    {
        log << "Error: Script file \'" << script << "\' cannot be opened or does not exist.\n" << endl;
        log.close();
        return -1;
    }

    //start parsing script file    
    int i = 0;
    int n;
    int size;
    int k;
    string line; // store each line in script file
    WordList *L; // array of word lists
    FreqList *F; // array of frequency lists which store the information of words and its frequency
    string *S; // array of strings which store the name of lists
    Hash HT; // hash table to store all the words
    L = new WordList[1000];
    F = new FreqList[1000];
    S = new string[1000];

    //initiate temporary lists and list nodes
    WordNode *tempWordNode;
    FreqNode *tempFreqNode;
    WordList tempWordList;
    WordList *tempWordListpt;
    FreqList tempFreqList;
    FreqList tempFreqList2;
    string tempString;
    Node *tempNode;

    int pos1;
    int pos2;

    log << "Begin parsing script file \'" << script << "\':\n" << endl;
    while(getline(indata, line))
    {
        log << line << '\n';
        SParser.ParseLine(line);

        //process to determine if listID exits
        int ID = -1; // cmd.listID, after following checking process, if it's still -1, then cmd.listID is a new list, otherwise cmd.listID is the word list L[ID] or frequency list F[ID]
        int ID2 = -1; // cmd.value1 (if it stores list name), same procesure as above
        int ID3 = -1; // cmd.value2 (if it stores list name), same procesure as above

        for (int j = 0; j < i; j++)
        {
            ID = (SParser.cmd.listID == S[j])?j:ID; // check if cmd.listID is already in S[]
        }

        if (SParser.operationCode() != 3 && SParser.operationCode() != 8 && SParser.operationCode() != 9 && SParser.operationCode() != 10 && SParser.operationCode() != 13 && SParser.operationCode() != 0 && ID == -1) 
        { 
            log << "Error: invalid operation, because list \'" << SParser.cmd.listID << "\' is not created yet.\n" << endl;
            if (SParser.operationCode() == 4 || SParser.operationCode() == 5)
            {
                ofstream output;
                output.open(SParser.cmd.value1.c_str());
                output << "List " << SParser.cmd.listID << " does not exist" << endl;
                output.close();
            }
            continue;
        }

        if ((SParser.operationCode() == 3 || SParser.operationCode() == 8 || SParser.operationCode() == 9 || SParser.operationCode() == 10 || SParser.operationCode() == 13) && ID > -1) 
        { 
            log << "Error: invalid operation, because list \'" << SParser.cmd.listID << "\' already exists.\n" << endl;
            continue;
        }

        // do all the list operations, such as read, insert, delete, write, intersection, union, load, filter, index and seach
        switch (SParser.operationCode())
        {
        case 1:
            n = L[ID].insert(SParser.cmd.value2, SParser.cmd.value1);
            if (n == -1) {
//.........这里部分代码省略.........
开发者ID:zhuoliu0920,项目名称:data-structures,代码行数:101,代码来源:keywordsearch.cpp


注:本文中的WordList::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。