#include<fstream>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
ifstream infile;
ofstream outfile;
infile.open("oldfile.txt");
outfile.open("newfile.txt");
while(infile){
string str,nstr;
infile>>str;
char charr[10];
charr[0]='<';charr[1]='\0';
nstr=str.substr(0,str.find_first_of(charr));
outfile<<nstr<<' ';
}
}
该程序使用 substr(0, string.find_first-of(charcter array which is starting point to be substring))每个单词的不必要的子字符串,但在写入另一个文件时它不保留行号。你能修好它吗 。它按顺序逐字写入文件。代码没有逐行保留,