أمثلة على التعامل مع الملفات في سي بلس بلس ++C
-
2020-10-05
- | daafoor
- | مشاهدات: 3444
كود الكتابة في ملف :
#include
#include
using namespace std;
int main() {
// Create and open a text file
ofstream MyFile("filename.txt");
// Write to the file
MyFile << "Files can be tricky, but it is fun enough!";
// Close the file
MyFile.close();
}
كود القراءة من ملف :
// Create a text string, which is used to output the text file
string myText;
// Read from the text file
ifstream MyReadFile("filename.txt");
// Use a while loop together with the getline() function to read the file line by line
while (getline (MyReadFile, myText)) {
// Output the text from the file
cout << myText;
}
// Close the file
MyReadFile.close();
هذه المادة الدراسية هي ضمن مكتبة
مكتبة تمارين بلغة البرمجة سي بلس بلس ++C
التعليقات
لا يوجد تعليقات
لاضافة سؤال او تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول
تسجيل الدخول