Reading next line of a file in c++ - Bdtunerexpress

Latest

Friday, March 2, 2018

Reading next line of a file in c++

 কিভাবে আপনি একটি ফাইল পরবর্তী  লাইন পড়া  এবং এটি প্রিন্ট আউট? এটা আমার কোড

  1. // reading a text file
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6. int main () {
  7. string line;
  8. ifstream myfile ("example.txt");
  9. if (myfile.is_open())
  10. {
  11. while (! myfile.eof() )
  12. {
  13. getline (myfile,line);
  14. if (line = something)
  15. {
  16. // read next line and print it... but how?
  17. }
  18. myfile.close();
  19. }
  20. else cout << "Unable to open file";
  21. return 0;

আপনার যদি বিবৃতি ভুল। আপনি সম্ভবত বোঝা == এবং না শুধু =; এছাড়াও getline () ইতিমধ্যে লাইন মধ্যে লাইন পড়া;
 যদি আপনি পরবর্তী লাইনে পড়তে চান, তবে আবারও getline () ব্যবহার করুন । এটি মুদ্রণ করার জন্য, শুধু std :: cout ব্যবহার করুন।


এছাড়াও, আপনার লুপের অবস্থানে eof () ব্যবহার করবেন না। পরিবর্তে ভাল () ব্যবহার করুন (যা নিখুঁতভাবে অনুসরণ করা যেতে পারে):
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. int main()
  6. {
  7. string line;
  8. ifstream myfile( "example.txt" );
  9. if (myfile) // same as: if (myfile.good())
  10. {
  11. while (getline( myfile, line )) // same as: while (getline( myfile, line ).good())
  12. {
  13. if (line == something)
  14. {
  15. ...
  16. }
  17. }
  18. myfile.close();
  19. }
  20. else cout << "fooey\n";
  21. return 0;
  22. }




How to install adobe premiere pro 2023 - কিভাবে Adobe Premiere PRO আপনার পিসিতে ইন্সটল করবেন

 How to install adobe premiere pro 2023 Download Premiere Elements Open the Adobe Premiere Elements download page in your web browser. Sign ...