我在 C++ 中创建动态表时遇到问题。我的程序中断并大喊:
xxx.exe 中 0x75914598 处的未处理异常:Microsoft C++ 异常:内存位置 0x0107F73C 处的 std::bad_alloc。
我知道我缺少一些东西,所以如果你能这么好心并指出我在哪里以及如何修复它。具有ll
随机值,(但即使我在下面的代码中设置了一个值,我也会遇到相同的错误,所以问题出在下面的代码上),它是在另一个函数中生成的(问题出在这个代码上:/)。
完整代码: http: //pastebin.com/Gafjd5Um
代码:
#include <iostream>
#include <math.h>
#include <cstdio>
#include <locale.h>
#include <conio.h>
#include <cstdlib>
#include <time.h>
#include <vector>
class GeneratePass
{
private:
//int length;
int ll=5;
char *lowertab;
public:
void ChooseLenght();
void CreateList();
GeneratePass()
{
lowertab = new char[ll];
}
~GeneratePass()
{
delete[] lowertab;
}
};
void GeneratePass::CreateList()
{
srand( time( NULL ) );
int i, j;
for( i = 0; i < ll; i++ )
{
lowertab[ i ] =( char )( rand() % 24 ) + 97;
}
for( i = 0; i < ll; i++ )
{
cout << lowertab[ i ];
}
}
int main()
{
GeneratePass create;
create.CreateList();
return 0;
}