How does vector split work?/ delimiter

So let say if i have something like this
hiAAAmyAAAnameAAAis
how do i use vector split to get rid of AAA and just get hi my name is
Last edited on
By "vector split", are you referring to boost::split using a vector as the first argument?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <string>
#include <vector>
#include <iostream>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

int main()
{
    std::string s = "hiAAAmyAAAnameAAAis";
    std::vector<std::string> v;
    
    split(v, s, boost::is_any_of("A"), boost::token_compress_on);
    
    for(auto& s: v)
        std::cout << s << '\n';
}


demo: http://coliru.stacked-crooked.com/a/189b103f00a0886e
i think my teacher was talking about like vector<string> v = split. I dont think we learned about boost yet.. is there another way to do this?
You'd have to explain what "split" means, then. It's not a name that's used anywhere in standard C++ (and in boost it's used as above). Is it a name of a function you're supposed to write?
Last edited on
Write a function that splits the string by a given delimiter. Function header is:
vector<string> split(stirng target, string delimiter);
for example, the code inside main calling your function
vector<string> v = split("hiAAAmyAAAnameAAAis", "AAA");
and v should come out as hi my name is

okay i got this far but its not giving me the answer.. help
#include <string>
#include <vector>
#include <iostream>

using namespace std;
vector<string> split (string target, string delimiter)
{
vector<string> thing;
thing.push_back(delimiter);
return thing;
}


int main () {
vector<string> v = split("hiAAAmyAAAnameAAAis", "AAA");
cout << v.at(0);
system ("pause");
return 0;
}
Topic archived. No new replies allowed.