调试断言失败文件,tokenScanner和文本文件 [英] Debug Assertion Failed File, tokenScanner, and text files

查看:179
本文介绍了调试断言失败文件,tokenScanner和文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序,一次处理文本文件并提取相关信息。我的程序适用于一些文本文件,而不是其他文件。通过我的程序无法运行的文件和没有程序的文件之间没有明显区别。



对于有问题的文件:


  1. 程序打开文件

  2. 它会一次读入并处理一行中的一个很好的块,因为它应该

  3. 但是,它达到了一个问题行并给出错误消息:



    调试断言失败的文件:
    f:/dd/vctools/crt_bld/self_x86/src/isctype.c
    行:56
    表达式:(无符号)(c + 1)< = 256




<当我进入调试器模式时,我的代码中的while(tokenScanner)循环似乎出现了问题。我提起了正在处理的问题行的内容,并比较了两个问题文件,我发现断言失败消息弹出< / li> 其中正在处理的最后一个令牌是>。我不清楚为什么这是一个问题。原始文本文件中的这个特定令牌与

  • < / li>< li 。因此扫描仪在这个字符串中遇到麻烦。
    任何关于为什么这样的想法,以及我如何解决这个问题?任何建议将不胜感激!



    以下是我代码的相关部分:

     code> #include< string> 
    #include< iostream>
    #include< fstream> //从文件获取数据
    #includefilelib.h
    #includeconsole.h
    #includetokenScanner.h
    #includevector.h
    #includectype.h
    #includemath.h

    using namespace std;


    / *原型函数* /
    void evaluate(string expression);
    向量< string> myVectorOfTokens; //将存储令牌
    向量< string> myFileNames;

    / *主程序* /
    int main(){

    / * STEP1:创建文件名列表
    的向量进行迭代结束处理* /
    ifstream infile; //声明变量引用文件列表
    string catchFile = promptUserForFile(infile,Input file:);
    字符串; //对应于包含列表文件的主文件中的行
    while(getline(infile,line)){
    myFileNames.add(line);
    }

    / *步骤2:迭代向量中包含的文件名* /
    int countFileOpened = 0; //跟踪已打开文件的数量

    for(int i = 1; i< myFileNames.size(); i ++){
    myVectorOfTokens.clear(); //重新设置每个新文件的令牌向量

    string fileName;
    string line2;
    ifstream inFile;
    fileName = myFileNames [i];

    inFile.open(fileName.c_str()); // open file convert c_str

    if(inFile){
    while(getline(inFile,line2)){
    evaluate(line2);
    }
    }

    inFile.close();
    countFileOpened ++;
    }
    return 0;
    }

    / *提取传记作者名称的功能* /
    void evaluate(string line){
    / *从文本创建令牌向量* /
    TokenScanner扫描器(行); //构造函数
    while(scanner.hasMoreTokens()){
    string token = scanner.nextToken();
    myVectorOfTokens.add(token);
    }
    }


    解决方案


    while(!inFile.eof()


    只是错误(几乎任何情况下)

      while(getline(inFile,line2))
    evaluate(line2);
    / pre>

    更好


    I have written a program that processes text files one at a time and extract relevant information. My program works well with some of the text files and not others. There is no obvious difference between the files that run seamlessly through my program and those that don't.

    As far as the problematic files are concerned:

    1. the program opens the file
    2. it reads in and processes a good chunk of the lines one at a time as it should
    3. But then it reaches a problem line and gives the error message:

      "Debug Assertion Failed File: f:/dd/vctools/crt_bld/self_x86/src/isctype.c Line: 56 Expression: (unsigned)(c+1) <= 256"

    When I enter the debugger mode the problem seems to arise from the "while(tokenScanner)" loop in my code below. I pulled up the content of the problem line being processed and compared that across a couple of problem files and I found that the Assertion Failure message pops up at </li> where the last token being processed is ">". It's not clear to me why this is a problem. This particular token in the original text file is contiguous with <li in the form </li><li. Therefore the scanner is having trouble half way throught this string. Any thoughts on why this is and how I can fix this? Any advice would be much appreciated!

    Here is the relevant portion of my code:

    #include <string>
    #include <iostream>
    #include <fstream> //to get data from files
    #include "filelib.h"
    #include "console.h"
    #include "tokenScanner.h"
    #include "vector.h"
    #include "ctype.h"
    #include "math.h"
    
    using namespace std;
    
    
    /*Prototype Function*/
    void evaluate(string expression);
    Vector<string> myVectorOfTokens; //will store the tokens
    Vector<string> myFileNames;
    
    /*Main Program*/
    int main() {
    
        /*STEP1 : Creating a vector of the list of file names 
                  to iterate over for processing*/
        ifstream infile; //declaring variable to refer to file list
        string catchFile = promptUserForFile(infile, "Input file:");
        string line; //corresponds to the lines in the master file containing the list files
        while(getline(infile, line)){
            myFileNames.add(line);
        }
    
        /* STEP 2: Iterating over the file names contained in the vector*/
        int countFileOpened=0; //keeps track of number of opened files
    
        for (int i=1; i< myFileNames.size(); i++){
            myVectorOfTokens.clear(); //resetting the vector of tokens for each new file
    
            string fileName;
            string line2;
            ifstream inFile;
            fileName= myFileNames[i];
    
            inFile.open(fileName.c_str());   //open file convert c_str
    
            if (inFile){
                while(getline(inFile, line2)){
                    evaluate(line2);
                }
            }
    
            inFile.close();
            countFileOpened++;
        }
        return 0;
    }
    
    /*Function for Extracting the Biographer Name*/
    void evaluate(string line){
        /*Creating a Vector of Tokens From the Text*/
        TokenScanner scanner(line); //the constructor
        while (scanner.hasMoreTokens()){
            string token=scanner.nextToken();
            myVectorOfTokens.add(token);
        }
    }
    

    解决方案

    while(!inFile.eof()

    is just wrong (in almost any case)

    while(getline(inFile, line2))
          evaluate(line2);
    

    is better

    这篇关于调试断言失败文件,tokenScanner和文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆