que je fais C++ programme qui lit infini en boucle,C++ textfile lecture infinie boucle while
Après avoir laissé utilisateur d'entrer le mois désiré et l'année. La boucle infinie et devenir sortie seulement "AAAAA ...."
Textfile (entrée)
1 9 2017 | 0112233445 | 20,00 5,00
2 9 2017 || 6,00 3,00
3 10 2017 | 0135792468 | 30,00 1,00
4 10 2017 | 0166778899 | 7,00 10,00
4 10 2017 | 0177001228 | 40,00 4,00
5 10 2017 | 0184040626 | 8,00 2,00
6 10 2017 | 0134567892 | 50,00 6,00 10 2017 | 0145678910 | 9.00 7.00
J'ai essayé d'utiliser
while (inS >> Jour >> Mois >> Année >> ch >> hpNO >> ch >> c_Charges >> sms_charges)
mais rien ne semble travailler.
Des suggestions pour résoudre ce problème? Merci d'avance.
void monthlyreport(char manager[])
{
\t SYSTEMTIME T;
\t GetSystemTime(&T);
\t int month, year; //userinput
\t char ch;//store delimitor
\t int count = 0;
\t
\t double Totalcallcharges = 0;
\t double Totalsmscharges = 0;
\t double Totalcharges = 0;
\t int Day,Month, Year;//for textfile reading
\t char hpNO[11];
\t double c_Charges =0;
\t double sms_charges =0;
\t string Months[] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
\t system("cls");
\t cout << "You choose : MONTHLY CHARGES REPORT ...";
\t cout << "\n\n Which month/year (mm yyyy)? ";
\t cin >> month;
\t cin >> year;
\t ifstream inS;
\t inS.open("Transaction.txt");
\t /*while (inS >> Day)
\t {
\t \t while (inS >> Month)
\t \t {
\t \t \t while (inS >> Year)
\t \t \t {
\t \t \t \t while (inS >> ch)
\t \t \t \t {
\t \t \t \t \t while (inS >> hpNO)
\t \t \t \t \t {
\t \t \t \t \t \t while (inS >> ch)
\t \t \t \t \t \t {
\t \t \t \t \t \t \t while (inS >> c_Charges)
\t \t \t \t \t \t \t {
\t \t \t \t \t \t \t \t while (inS >> sms_charges)
\t \t \t \t \t \t \t \t {
\t \t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t \t \t \t if (month == Month && year == Year)
\t \t \t \t \t \t \t \t \t \t {
\t \t \t \t \t \t \t \t \t \t \t Totalcallcharges += c_Charges;
\t \t \t \t \t \t \t \t \t \t }
\t \t \t \t \t \t \t \t \t \t if (month == Month && year == Year)
\t \t \t \t \t \t \t \t \t \t {
\t \t \t \t \t \t \t \t \t \t \t Totalsmscharges += sms_charges;
\t \t \t \t \t \t \t \t \t \t }
\t \t \t \t \t \t \t \t \t \t count++;
\t \t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t \t }
\t \t \t \t \t \t \t }
\t \t \t \t \t \t }
\t \t \t \t \t }
\t \t \t \t }
\t \t \t }
\t \t }
\t }
*/
while (!inS.eof()) correct answer
\t \t \t {
\t \t \t \t inS >> tranS.day >> tranS.month >> tranS.year >> ch;
\t \t \t \t inS.getline(tranS.phoneNO, 12, '|');
\t \t \t \t inS >> tranS.call_charges >> tranS.sms_charges;
\t \t \t \t transactions(&head, tranS);
\t \t \t \t if (tranS.month == month &&tranS.year == year)
\t \t \t \t {
\t \t \t \t \t tranS.Total_call_charges += tranS.call_charges;
\t \t \t \t \t tranS.Total_sms_charges += tranS.sms_charges;
\t \t \t \t }
\t \t \t \t count++;
\t \t \t } \t
\t Totalcharges = Totalcallcharges + Totalsmscharges;
\t inS.close();
\t system("cls");
\t cout << Month << year;
\t cout << endl << c_Charges;
\t cout << setw(50) << setfill('=') << " " << endl << endl;
\t cout << " T A R U C M O B I L E S D N B H D" << endl << endl;
\t cout << setfill(' ') << setw(30) << "Monthly Report - " << Months[month - 1] << " " << year << endl;
\t cout << "\nTotal Number of TARUCMOBILE users = " << count;
\t cout << "\n\nTotal Charges from Calls = RM" << setw(8) << setfill(' ') << Totalcallcharges << setprecision(2);
\t cout << "\nTotal Charges from SMS's = RM" << setw(8) << setfill(' ') << Totalsmscharges << setprecision(2);
\t cout << "\n" << setfill(' ') << setw(27) << " " << right << setw(12) << setfill('-') << "-" << endl;
\t cout << "TOTAL CHARGES (POSTPAID) = RM" << setw(8) << setfill(' ') << Totalcharges << setprecision(2);
\t cout << "\n" << setw(27) << setfill(' ') << " " << setw(12) << setfill('=') << "=" << endl;
\t cout << "*** E N D O F R E P O R T *** " << endl << endl;
\t cout << "Generated by" << endl;
\t cout << "______________" << endl;
\t cout << manager << "(Manager)" << endl;
\t cout << T.wDay << " " << Months[T.wMonth - 1] << " " << T.wYear << endl;
\t cout << endl << setw(50) << setfill('=') << " " << endl;
\t
\t system("pause");
}
Possible duplicata de [Pourquoi iostream :: eof est-il dans une condition de boucle considérée comme incorrecte?] (Https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered- mauvais) – user0042
Merci, mais n'ont pas encore résolu mon problème. – JLXW
format, supprimer inutiles et fixes typo – user7294900