الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف أقرأ مصفوفة من ملف؟؟

مغلق
بدأه برمجة في 2 مايو 2003 · 2 رد · 704 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله و بركاته

يوجد مصفوفة ارقام مخزنة في ملف اريد ان اقرأها و لكن يظهر في الـrun أرقام عشوائية ...

هذا كود التخزين

#include<iostream>

#include<fstream>

#include<conio>

int main()

{

  int num,number[20];

  ofstream outfile("data.txt");

   cout<<"Enter how many number you like enter: ";

    cin>>num;

  outfile<<num;

   cout<<"Enter the number:";

    for(int i=0;i<num;i++)

     cin>>number;

    for(int i=0;i<num;i++)

     outfile<<number;

    cout<<"file written";

getch();

return 0;

}

هذا كود القراءة

ifstream in("data.txt");

    in>>num;

    for(int i=0;i<num;i++)

     in>>number;

     for(int i=0;i<num;i++)

    cout<<number;

أرجوا تصحيح الأكواد إذا كان فيها خطأ

شكرا لكم....

#2

لماذا لا تستخدم ما يلي فهو أسهل :

FILE * pf;

pf = fopen(FileNam,"w");

for (i=0; i < N; i++)

fprintf("%i ",mat);

الكود السابق من أجل الكتابة إلى ملف

pf = fopen(FileNam,"r");

for (i=0; i < N; i++)

{

fscanf("%i ",mat);

cout << mat << " ";

}

#3

I have corrected the Code

this code save one vectoronly but it cann't save a Matrix , if u want to save a matrix please send me and Icorrect it

#include
#include
#include
int main()
{
int i;
  int num1,num2;
  int number1[20],number2[20];

  ofstream outfile("data.txt");
   cout<<"Enter how many number you like enter: ";
    cin>>num1;
  outfile<   cout<<"Enter the number:";
    for(i=0;i     cin>>number1;
    for(i=0;i     outfile<<"n"<
	outfile.close();

	cout<<"file written";

ifstream in("data.txt");
    in>>num2;
    for( i=0;i         in>>number2;
    for( i=0;i         cout<<"n"<       in.close();
return 0;
}
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء

هذا الموضوع مغلق.

مواضيع مشابهة