1.问题:使用C语言删除文本文档中的一行数据##
解决:test.txt 是要被删除一行数据的文本
#include<iostream>
#include<fostream>
using namespace std;
void Delete() {
int i=0;
ifstream intf("test.txt");
ofstream out("tmp.txt");
string str1;
while( intf >> str1 )
{
if ( i == 0 )
{
i=1;
continue;
}
out << str1 << endl ;
}
out.close() ;
intf.close() ;
ifstream intff("tmp.txt");
ofstream outt("test.txt");
while( intff >> str1 )
{
outt << str1 << endl ;
}
intff.close();
outt.close() ;
}
本文介绍了一种使用C语言从文本文档中删除特定行的方法。通过创建临时文件来绕过要删除的行,然后将处理后的数据写回原始文件。此过程包括读取源文件、跳过指定行并复制其余内容。
1002





