C++ dasturlash tilida ma’lumotlarning faylli toifasi
Download 21.78 Kb.
|
22-variant
1- misol. uqish.txt fayldan ikkita sonni o’qib, ularni yig’indisini yozish.txt fayliga yozish dasturini ko’rib chiqamiz.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { StreamWriter yozish = new StreamWriter("d:\\yozish.txt"); StreamReader uqish = new StreamReader("d:\\uqish.txt"); yozish.WriteLine(int.Parse(uqish.ReadLine()) + int.Parse(uqish.ReadLine())); yozish.Close(); uqish.Close(); } }
Dastur natijasi: dasturni ishlatishdan oldin uqish.txt faylda 2 ta son kiritish kerak, so’ng dastur ikkita sonni o’qib, ularni yig’indisini yozish.txt fayliga yozadi. Natijani ko’rish uchun yozish.txt faylni ochib ko’rish kerak 2-misol. fayl davomidan ma’lumotlarni yozish. class Program { static void Main(string[] args){ /*textFile.txt faylining yangi satridan "yangi satr" so'zini qo'shadi agar bu fayl bo'lmasa o'zi yaratib "yangi satr" so'zini qo'shadi*/ StreamWriter a; a = File.AppendText("d:\\textFile.txt"); a.WriteLine("yangi satr"); a.Close(); } }
Download 21.78 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling