欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Run-Time Check Failure #3 - The variable 'side' is being used without being defined.

程序员文章站 2022-06-15 13:54:23
...

案例一:

#include "iostream"
using namespace std;
void main()

{
    int a;
    cout << a << endl;
}

Release下运行:
Run-Time Check Failure #3 - The variable 'side' is being used without being defined.
Debug下运行:

Run-Time Check Failure #3 - The variable 'side' is being used without being defined.

解决办法:

  • 方法1:a定义为全局变量
  • 方法2:给a赋个初值

案例二:

#include "iostream"
using namespace std;
void main()

{
    FILE* pFile = fopen("1.txt", "r");
    char* pBuf;
    fgets(pBuf, 1024, pFile);
    fclose(pFile);
    cout << pBuf << endl;
}

Debug下运行:
Run-Time Check Failure #3 - The variable 'side' is being used without being defined.
解决方案:

char* pBuf=(char *)malloc(1024);

或者

char pBuf[1024];

pBuf是一个字符型指针,因为赋指时没有为pBuf分配内存空间,所以pBuf的指向是不确定的,那么pBuf就有可能指向内存的重要区域
如果真要这么用,要先分配空间char* pBuf=(char *)malloc(1024);