ofstream books(“bo’lim1.dat”);
2) ifstream name(“ path\file_name”); - faylni undan ma’lumotlar o’qish uchun ochadi.
Masalan: ifstream book(“c kitob\bob\bo’lim1.dat”);
ifstream books(“\bo’lim1.dat”);
O’qish va yozish uchun ochilgan fayllarni albatta yopish kerak - name.close();
Book.close(): books.close();
1-masala. Berilgan 10 ta butun sondan ifodat A massivning musbat elementlarini F faylga yozing. (dastur konsol rejimida bajariladi).
#include
#include
#include
#include
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{ int a[10], i;
ofstream file("musbat.txt");
file<<"A massivining musbat elementlari"<for(i=1;i<=10;i++)
{
cout<<"a["<>a[i];
if (a[i]>0) file<<" "<}
file.close();getch();
return 0; }
Do'stlaringiz bilan baham: |