C++ dasturlash tilida ma’lumotlarning faylli toifasi
Download 21.78 Kb.
|
22-variant
3- misol. fayldan ma’lumotlarni bitta bitta belgi orqali o’qish va chiqarish.
class Program { [STAThread] static void Main(string[] args) { StreamReader uqish; try
{ uqish = new StreamReader("d:\\textFile.txt"); } catch {
Console.WriteLine("Faylni ochishda xatolik bor"); Console.ReadKey(); return; } int ch;
while ((ch = uqish.Read()) != (-1)) { Console.WriteLine((char)ch); } Console.ReadKey(); } }
class Program { static void Main(string[] args) { FileStream a = new FileStream("d:\\a.txt", FileMode.CreateNew); BinaryWriter w = new BinaryWriter(a); //faylga ma'lumotlarni yozamiz for (int i = 1; i < 20; i++) { w.Write( (int) i); } //faylni yopish w.Close(); a = new FileStream("d:\\a.txt", FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(a); // fayldan ma’lumotlarni o’qiymiz for (int i = 1; i < 20; i++) { Console.WriteLine(r.ReadInt32()); } r.Close(); Console.ReadKey(); } }
5- misol. fayldan ma’lumotlarni satrma - satr o’qish. class Program { static void Main(string[] args){ FileStream a = new FileStream("d:\\textFile.txt", FileMode.Open, FileAccess.Read); StreamReader b = new StreamReader(a); string s; while ((s = b.ReadLine()) != null){ Console.WriteLine(s); } b.Close(); Console.ReadKey(); } }
Download 21.78 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling