我在VS2010中编写了一个读取INI文件的程序,可是在运行是出现Debug Assertion Failed! Program: G: \ \ Debug \ project project practice practice. Exe File: f: \ dd \ vctools \ crt_bld \ self_x86 \ CRT \ SRC \ xtoa. C Line: 142 - Expression: "sizeInTChars length For information on how your program can cause an assertion Failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) 错误,通过调试发现代码功能可以实现,就是在跳出循环的的时候出现这个问题!

解决方案 »

  1.   

    void CombindStr(char *str1,const char *str2,int i)
    {
    char keyNum[3];
    strcpy_s(str1,20,str2);
    _itoa_s(i,keyNum,10); 
    strcat_s(str1,20,keyNum);
    }void GetInitStr(const char * name,const char * key,int i,char * reStr)
    {
    char keyCode[20];
    CombindStr(keyCode,key,i);
    GetPrivateProfileString(name,keyCode," ",reStr,200,".\\项目练习.ini");
    }
    void ADapp::InitBasePara(void)
    {
    int i;
    Lan_Dis = GetPrivateProfileInt("other","LanDis",100,".\\项目练习.ini"); for(i=0;i<250;i++)
    {
    GetInitStr("International","LanKey_",i,InterCode[i].LanKey);
    GetInitStr("International","LanE_",i,InterCode[i].LanE);
    GetInitStr("International","LanS_",i,InterCode[i].LanS);
    }
    }
    这是代码
      

  2.   

    InterCode[i]这个结构体数组是如何声明的额,感觉像是指针越界了
      

  3.   

    这个结构体在.h文件的类外定义,就是头文件下面,在类内有声明,是用来存放读入的INI文件内容的!
      

  4.   

    既然断点了。这个问题应该很好解决吧?Debug Assertion Failed问题出现点击重试,可以看到崩溃代码。这时候看看各个变量的值就可以得到答案了。
      

  5.   

    1024DA70   int         3
    调试到这里显示异常