কম্পিউটার

C++ ifstream সহ একটি পাঠ্য ফাইল থেকে পূর্ণসংখ্যা পড়ুন


এখানে C++ ifstream সহ একটি পাঠ্য ফাইল থেকে পূর্ণসংখ্যার পাঠের একটি উদাহরণ।

উদাহরণ

#include <fstream>
#include<iostream>
using namespace std;
int main() {
   //initialie the array size
   int arr[30];
   ifstream is("a.txt");
   int cnt= 0;
   int x;
   // check that array is not already full
   while (cnt < arr[30] && is >> x)
   // and read integer from file
   arr[cnt++] = x;
   // print the integers stored in the array
   cout<<"The integers are:"<<"\n";
   for (int i = 0; i < cnt; i++) {
      cout << arr[i] <<' ';
   }
   //close the file
   is.close();
}

আউটপুট

The integers are:
1 2 3 4 5 6 7

  1. কিভাবে C++ এ একটি টেক্সট ফাইলে টেক্সট যুক্ত করবেন?

  2. C++ এ স্ট্রিং থেকে সমস্ত পূর্ণসংখ্যা বের করুন

  3. পাইথন ব্যবহার করে একটি পাঠ্য ফাইল থেকে একটি সম্পূর্ণ লাইন কিভাবে পড়তে হয়?

  4. কিভাবে পাইথন ব্যবহার করে একটি টেক্সট ফাইল থেকে বেশ কয়েকটি অক্ষর পড়তে হয়?