Menu
Coddy logo textTech

מעבדת תרגול מס׳ 1

שיעור 6 מתוך 23 בקורס טיפול בקבצים ב-C++ של Coddy.

challenge icon

אתגר

קל

*אל תשנה את הקוד במקומות שבהם אסור לך*

נסה לפתוח 3 קבצים:

  • code.txt
  • script.txt
  • novel.txt

פתח אותם ובדוק כל אחד מהם לפי הסדר כדי לראות אם אפשר לפתוח אותו, ואז הדפס את ההודעה File opened אם אפשר, ואת Unable to open file אחרת.
לאחר מכן, סגור רק את הקבצים code.txt ו-novel.txt.

*הדפס כל הודעה בשורה חדשה*

נסו בעצמכם

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    //-------------------------
    
    ifstream file_code;
    ifstream file_script;
    ifstream file_novel;
    
    // הכניסו את הקוד שלכם כאן
    
    
    //-------------------------
    
    // אל תשנו את הקוד מכאן והלאה
    
    if(!file_code.is_open())
        cout << "File closed" << endl;
    else
        cout << "File still opened" << endl;
        
    if(!file_script.is_open())
        cout << "File closed" << endl;
    else
        cout << "File still opened" << endl;
        
    if(!file_script.is_open())
        cout << "File closed" << endl;
    else
        cout << "File still opened" << endl;
    
    return 0;
}

כל השיעורים ביחידה טיפול בקבצים ב-C++

תרגלו בעצמכם: קומפיילר C++ אונליין