Hello,
I have a file called "test.txt" which contains something like this:
aaaaaaa, 12312311, zzzzzz, 2312312, asdasdas, 1232312
ddddddd, 12312, cccccccccccc, 312312312, sdasdasds, 1112
eqweeqeeqw, 12312311, dasdass, 2312312, asdasdas, 1232312
ccaascadc, 12312, ccacacacecaeeda, 312312312, sdasdasds, 1112
eqweeqeeqw, 12312311, dasdass, 2312312, asdasdas, 1232312
ccaascadc, 12312, ccacacacecaeeda, 312312312, sdasdasds, 1112
What I need is to create a file called "test2.txt" which contains only selected informations from the file mentioned above. For example it would contain only
aaaaaaa, zzzzzzzz
ddddddd, cccccccccccc
...and so on, in other words, the destination file must contain only two of the columns from the first file.
Now, what Ive tried to do to achieve this was to copy all the contents of the first file in a vector<string>, thinking that afterwards I could select and extract only the data I need from that vector.
So now I have a vector that has in it the contents of the first file, but I dont know how to extract what I need from it.Code:#include <fstream>
#include <vector>
#include <string>
using namespace std;
void main()
{
fstream file1;
ofstream file2;
string s, s2;
vector<string> v;
file1.open("C:\\test.txt");
file2.open("C:\\test2.txt");
while(getline(file1, s2))
{
s += s2 + "\n";
v.push_back(s);
}
for (int i=0;i<v.size();i++)
{ file2<< v[i]; }
file1.close();
file2.close();
}
Thank you in advance for any suggestion.
Regards,
