I have a file that contains lines that look like this:
uniquemember: uid=vojk,ou=people,dc=cms,dc=gov
uniquemember: uid=p2o9,ou=people,dc=cms,dc=gov
etc.
I'm trying to isolate and get - the four letter code sandwiched in between everything (vojk, p2o9). That's all I want to printed out.
I've been looking around and I see that there's a function called "erase" that I can use to try and erase certain parts of the line. However, when I try, I keep getting out of bound errors and it keeps saying "std::out_of_range" and ' > this-> size() (which is 0) '
I'm not sure what I'm doing wrong. Here is my code. I sincerely appreciate your help. Thank you in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main()
{
vector<string> v;
vector<string> junk;
ifstream infile;
infile.open("list.txt");
if (infile.fail())
{
cout << "Could not open file." << "\n";
return 1;
}
string data;
string str ("dn");
string str2 ("uniquemember: ");
//infile >> data;
while (getline(infile, data)) {
transform(data.begin(), data.end(), data.begin(),
[](unsigned char c) { return tolower(c);});
//data.erase(data.length()-10);
if (data.find(str) != string::npos) {
junk.push_back(data);
}
else {
v.push_back(data);
}
}
sort(v.begin(), v.end());
auto last = unique(v.begin(), v.end());
v.erase(last, v.end());
for (const auto& i : v)
cout << i << " " << endl;
}
|