静的な値をC++のリストコンテナに格納したい。私のコードを実行した後、これは何のエラーもなくクラッシュします。たぶんあなたは何が間違っているかを見ますか? 私は100値のリストを客観的に作成しようとしていて、リストにランダムな値を加え、後でcmdでそれを印刷します。乱数をリストに格納する方法は? C++
ありがとうございます。
#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;
}
デバッガを使用する時間(学習方法) – UnholySheep
「r [n];」とは何でしょうか? – Rakete1111
このような問題を解決する適切なツールは、デバッガです。スタックオーバーフローを尋ねる前に、コードを一行ずつ進める必要があります。詳しいヘルプは、[小さなプログラムをデバッグする方法(Eric Lippert)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)を参照してください。少なくとも、問題を再現する[最小、完全、および検証可能](http://stackoverflow.com/help/mcve)の例と、デバッガでの観察結果を含めるように質問を編集する必要があります。 –