I want to store static number of value into my list container in c++. After I run my code, this one crash without any error. Maybe you see what is wrong? I am trying objectively create list of 100 values and then add random value to a list and later to print it out in cmd.
Thanks in advance.
#include <cstdlib>
#include <iostream>
#include <list>
#include <stdlib.h>
using namespace std;
class LIST
{
private:
int *r;
int n;
public:
LIST(); // 1 konstr
void input();
void show();
};
// ====================================
LIST::LIST() // 1 konstr
{
n = 100;
list<int> r(n);
}
// ====================================
void LIST::input()
{
r[n];
for (int i = 0; i < n; ++i) {
r[i] = rand() % 100 + 1;
}
}
// ====================================
void LIST::show()
{
cout << "1D input\n";
for (int i=1; i<=n; i++)
{
cout << i << " "; cout << r[i] << endl;
}
cout << "**********************************************\n";
}
// ====================================
int main(int argc, char *argv[])
{
LIST wow;
wow.input();
wow.show();
system("pause");
return EXIT_SUCCESS;
}
Aucun commentaire:
Enregistrer un commentaire