-
February 2nd, 2007, 05:46 PM
#1
problem with a vector
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.
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();
}
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.
Thank you in advance for any suggestion.
Regards,
the doer alone learneth. (nietzsche)
-
February 2nd, 2007, 06:03 PM
#2
Re: problem with a vector
Cheers,
Alex
Please rate this post if you find it helpful
-
February 2nd, 2007, 06:12 PM
#3
Re: problem with a vector
Hello,
Thank you very much for your help.
the doer alone learneth. (nietzsche)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|