输入的数字与结果不一样
The number entered isn't the same as the result
我的代码有问题,debit.txt
的结果与输入的不一样:
long int s;
ofstream outfile;
outfile.open("saldo.txt");
cout << "Masukan jumlah saldo kredit : "; cin >> s;
outfile << s << endl;
outfile.close();
我的saldo.txt
long int db;
ofstream outfile;
outfile.open("debit.txt");
cout << "Masukan jumlah saldo kredit : "; cin >> db;
outfile << db << endl;
outfile.close();
我的debit.txt
long int s, db;
ifstream infile;
infile.open("saldo.txt");
infile >> s;
cout << s << endl;
infile.open("debit.txt");
infile >> db;
cout << db << endl;
infile.close();
}
这就是结果 cek.txt
当我尝试在 debit.txt
中输入 150 时,结果是一个随机数,但 saldo.txt
却不是,有人可以帮我解决这个问题吗? :)
您在打开 "debit.txt" 之前没有关闭 "infile" 对象。
请按照下面的说明关闭 infile
long int s, db;
ifstream infile;
infile.open("saldo.txt");
infile >> s;
cout << s << endl;
infile.close(); //close here.
infile.open("debit.txt");
infile >> db;
cout << db << endl;
infile.close();
我的代码有问题,debit.txt
的结果与输入的不一样:
long int s;
ofstream outfile;
outfile.open("saldo.txt");
cout << "Masukan jumlah saldo kredit : "; cin >> s;
outfile << s << endl;
outfile.close();
我的saldo.txt
long int db;
ofstream outfile;
outfile.open("debit.txt");
cout << "Masukan jumlah saldo kredit : "; cin >> db;
outfile << db << endl;
outfile.close();
我的debit.txt
long int s, db;
ifstream infile;
infile.open("saldo.txt");
infile >> s;
cout << s << endl;
infile.open("debit.txt");
infile >> db;
cout << db << endl;
infile.close();
}
这就是结果 cek.txt
当我尝试在 debit.txt
中输入 150 时,结果是一个随机数,但 saldo.txt
却不是,有人可以帮我解决这个问题吗? :)
您在打开 "debit.txt" 之前没有关闭 "infile" 对象。 请按照下面的说明关闭 infile
long int s, db;
ifstream infile;
infile.open("saldo.txt");
infile >> s;
cout << s << endl;
infile.close(); //close here.
infile.open("debit.txt");
infile >> db;
cout << db << endl;
infile.close();