#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配列))を使用して各単語の不要なサブストリング別のファイルに書き込むときに行番号を保持しません。あなたはそれを修正できますか?単語単位でファイルワードをシーケンシャルに書き込みます。コードはこれではなく、単一の空白文字でsperatingの行ずつ記述しますファイル内の単語を切り取り、C++で行番号を保存して書き込む
outfile<<nstr<<' ';
outfile<<nstr<<endl;
に
VTC:Plzはコードを送信します。 –