注册 登录
编程论坛 C++教室

C++如何实现删除文本空行的功能

chaw899 发布于 2019-06-28 17:17, 2472 次点击
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
 
int main()
{
    ifstream in("hui.txt");
    ofstream out("2.txt");
    string filename;
    string line;
 
    if(in) // 有该文件
    {
        while (getline (in, line))     // line中不包括每行的换行符
        {
            cout << line << endl;
            out << line << endl;       // 输入到2.txt中
        }
    }
    else // 没有该文件
    {
        cout <<"no such file" << endl;
    }
 
    return 0;
}




[此贴子已经被作者于2019-6-30 17:23编辑过]

3 回复
#2
rjsp2019-06-28 18:32
if( !line.empty() )
#3
chaw8992019-06-30 17:26
回复 2楼 rjsp
复制文本的时候,如果当前行的字符数不超过5个,
就删除此行应该如何判断?
#4
rjsp2019-07-01 08:21
回复 3楼 chaw899
if( line.size() <= 5 )
1