在2010 Visual C ++ Express中,我正在使用 ...
ifstream inFile("inputfile.dat");
double number;
while(inFile >> number)
{
cout << number << endl;
}
...将存储在文件中的8个数字读入程序,并在监视器上显示。它会根据需要正确显示它们,但我需要将每个单独的数字存储为已指定的双精度数。从上到下,
那么其他4个数字对于不同的客户来说都是一样的。我尝试了很多不同的方法,但每个方法都有:
"Run-Time Check Failure #3 - The variable 'variableName' is
being used without being initialized."
几乎所有变量都会发生这种情况。我已经搜索了任何可以帮助我的东西,但似乎找不到能帮助我达到我需要的程度的东西。
答案 0 :(得分: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";
}