الشرح التفصيلي لجميع شرائح المحاضرة (Slide-by-Slide) مدعوم بشرح الأكواد سطراً بسطر (Line-by-Line Code Explanation)
1. Which file mode should you use if you want to write new data to the END of an existing file without deleting its current contents?
2. What is the correct class to use if you ONLY want to READ data from a file into your program?
1. What is the primary purpose of the `try` block in Exception Handling?
2. What happens to the program's execution immediately after a `throw` statement is executed inside a `try` block?
cin (من الكيبورد)، cout (للشاشة). مكتبة fstream بتضيف تيارات للملفات.ofstream (كتابة فقط)، ifstream (قراءة فقط)، fstream (الاتنين).ios::out (كتابة بمسح القديم)، ios::in (قراءة)، ios::app (إلحاق من غير مسح)، ios::trunc (مسح كامل)..close(): عشان تضمن إن البيانات اتكتبت والملف اتقفل بأمان.getline(): بتقرا سطر كامل (بالمسافات). بنستخدمها في while loop عشان نقرا الملف كله لحد الآخر (EOF).try (حط الكود الخطير)، throw (ارمي الخطأ)، catch (امسك الخطأ واتعامل معاه). البرنامج مبيقفلش!if (!outFile) { ... } قبل ما تبدأ تكتب فيه.Question: Explain File I/O in C++ using the `fstream` library. Discuss the three main classes (`ofstream`, `ifstream`, `fstream`) and the different file opening modes. Then explain Exception Handling using `try`, `throw`, and `catch` with a practical example.
Q1:
Q2:
Q1: Include the necessary library for File Input/Output operations.
Q2: Open a file named log.txt for writing in APPEND mode so previous data isn't deleted.
Q3: Write a line of code that reads an entire string containing spaces from the keyboard into a string variable fullName.
a) What is the purpose of the if (!inFile) check?
b) What does the condition while (inFile >> num) do?
c) What is the direction of the stream arrows (>>) when reading from a file, and what do they point to?