c++ - How to get the last but not empty line in a txt file -


I do not want to get a last but empty line in a txt file.

This is my code:

string line1, line2; Ifstream myfile (argv [1]); If (myfile.is_open ()) {while (! Myfile.eof ()) {getline (myfile, line1); Line 1! = "\ T" || Line 1! = "\ N" || Line 1. Command ()) Line 2 = Line 1; } Myfile.close (); } And cout & lt; & Lt; "unable to open file";

The problem is that I can not check the empty line.

To check this, enter your & quot; & Quot; Would not it be enough to change whether the line is empty if there are seven places, one tab character, another 3 spaces and finally a new line? You can not list all the methods to get only white space in a line. Instead, check each character in the line to see if it is white space.

In this code, is_empty would be incorrect if there are no non-space characters in the line.

  bool is_empty = true; For (int i = 0; i  

Complete Solution:

#include & lt; Iostream & gt; # Include & lt; Fstream & gt; # Include & lt; Cctype & gt; #include & lt; String & gt; using namespace std; Int main (int argc, char * argv []) {string string; String end_line; Ifstream myfile (argv [1]); If (myfile.is_open ()) {while (getline (myfile, line)) {bool is_empty = true; For (int i = 0; i

Comments