1

2010 Visual C++ Express では、使用しています ...

ifstream inFile("inputfile.dat");
double number;
while(inFile >> number)
{
cout << number << endl;
}

...ファイルに保存されている 8 つの数値をプログラムに読み込み、モニターに表示します。それらはすべて正しく必要に応じて表示されますが、個々の数値を既に指定されている double として保存する必要があります。上から下まで、

  1. 顧客 1 の識別番号
  2. バランス
  3. 未払いの支払い
  4. 行われた購入

残りの 4 つの番号は、別の顧客の場合と同じです。私はそれを行うためにさまざまな方法を試しましたが、それぞれに次のものが付属しています。

"Run-Time Check Failure #3 - The variable 'variableName' is 
 being used without being initialized."

そしてそれはほとんどすべての変数で起こります。これに役立つものを探しましたが、必要な範囲で役立つものを見つけることができなかったようです.

4

1 に答える 1

2

これらをいくつかの集計データ型ではなく、8 つの個別の変数に格納する必要があると仮定します。

std::ifstream inFile("inputfile.dat");
double number;

    if(inFile >> cust1id >> cust1bal >> cust1pay >> cust1purch >> 
                 cust2id >> cust2bal >> cust2pay >> cust2purch) {
      std::cout << 
        "Customer 1's Identification #: " << cust1id << "\n" <<
        "Balance: " < cust1bal << "\n" <<
        "Payments outstanding: " << cust1pay << "\n" <<
        "Purchases that have been made: " << cust1purch << 
        "Customer 2's Identification #: " << cust2id << "\n" <<
        "Balance: " < cust2bal << "\n" <<
        "Payments outstanding: " << cust2pay << "\n" <<
        "Purchases that have been made: " << cust2purch << "\n"; 
     }
于 2012-10-22T01:27:43.580 に答える