#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<<' ';
}
}
this program uses substr(0, string.find_first-of(charcter array which is starting point to be substring))each word’s unnecessary sub strings but it doesn’t preserve the line number when writing to another file. can you fix it . it writes the file word by word sequencially. the code didn’t preserve line by line,
string input doesn’t care about line boundaries, it treats \n,\t,\v and probably others the same as space.