C++逐行读取为文本并进行过滤(空行和字符长度)
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// 逐行读取文本,遇到空行跳过,并且遇到字符长度进行过滤
int main ()
{
ifstream f("..\\test.txt");
string line;
if (f)
{
while (getline(f, line))
{
//cout << line.size() << endl;
if (!(line.empty())&& (line.size)()>10)
{
cout << line << endl;
}
}
}
else
{
cout << "no such file" << endl;
}
}