I wonder how to split a string, right before integer. Is it possible? I have written a converter that downloads data from an old txt file, edits it, and saves it in a new form in a new txt file.
For example old file look like:
Every data in new row. New file after convert should look like:
Means that all data after integer should be in a new different line.
My code is included below. Now I have one string as a buf without any white signs:
And I want to split it as shown in the example.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main () {
string fileName;
cout << "Enter the name of the file to open: ";
cin >> fileName;
ifstream old_file(fileName + ".txt");
ofstream new_file("ksiazka_adresowa_nowy_format.txt");
vector <string> friendsData;
string buf;
string data;
while(getline(old_file, data)) {
friendsData.push_back(data);
}
for(int i=0; i<friendsData.size() ; ++i) {
buf+=friendsData[i] + '|';
}
new_file << buf;
old_file.close();
new_file.close();
return 0;
}