【发布时间】:2019-12-03 05:57:12
【问题描述】:
我正在尝试打印文件的内容,但我不确定如何忽略文件中的空白行。
当前代码:
if(option == "-ps"){
while(getline(instream, str)){
if(str.length() == 0){
continue;
}
cout << str << endl;
}
}
文件内容
Department meeting | 2019 |10 |29 |9:30 aM |15
Meeting with Bob | 2019 |10 |29 |8:30 aM |15
Meeting with Jim | 2019 |10 |29 |9:00 aM |15
Doctor's appointment | 2019 |10 |29 |10:30 aM |15
Meeting with Bob | 2019 |10 |29 |11:30 aM |15
Lunch meeting with dean | 2019 |10 |29 |11:45 aM |15
Lunch with the guys | 2019 |10 |29 |12:30 pM |60
Lunch with the guys | 2019 |10 |29 |12:30 pM |60
Lunch with the guys | 2019 |10 |29 |12:30 pM |60
Meeting With BOB | 2019 |10 |29 |1:30 pM |15
Chair meeting | 2019 |10 |29 |2:30 PM |15
Meeting WITH Bob | 2019 |10 |29 |3:30 pm |20
Fishing with Donald and Donald|2019|11|30|8:14AM| 115
Fishing with Donald and Billy| 2019|12|11 | 2:45 PM|15
Appointment with Donald|2019 |12|5|8:56PM |115
Appointment with Fred|2019|12|1|8:30PM|50
Lunch|2019|12 | 1|10:58PM |115
Fishing with Bob and Fred|2019 |12| 3| 2:45PM|10
Skiing with Juedes| 2019|12 | 8|9:15 am|60
我当前的代码将打印出文件内容,但仍会打印空白行。我试图用第二个 if 语句来解决这个问题,但它似乎不起作用。
感谢任何帮助。
【问题讨论】: