I've got problem creating a dynamic table in c++. My program breaks and shouts:
Unhandled exception at at 0x75914598 in xxx.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0107F73C.
I know there is something I'm missing so if could you be so kind and point me where and how to repair it.
The ll
has random value, (but even if I set a value like in code underneath I'm getting same error, so the problem is with following code), which is ganerated in another function (problem is with this code :/).
Full code: http://pastebin.com/Gafjd5Um
Code:
#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;
}