1

在 2010 Visual C++ Express 中,我正在使用...

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

...将存储在文件中的 8 个数字读入程序中,并在监视器上显示。它根据需要正确显示它们,但我需要将每个单独的数字存储为已经指定的双精度数。从上到下,

  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 回答