#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(部分文字列の開始点である文字配列))各単語の不要な部分文字列を使用しますが、別のファイルに書き込むときに行番号を保持しません。あなたはそれを修正できますか?ファイルを単語ごとに順番に書き込みます。コードは行ごとに保存されませんでした。