I worked a little bit with javascript and I decided to work on a function that will work similar to str.split(), but in C++. The next code I wrote shows me this error:
no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=char, _Alloc=std::allocator]" matches the argument list -- argument types are: (char *) -- object type is: std::vector>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
vector<char> split(char str[], char spliter[]){
unsigned i=0;
vector <char> output;
char *p = strtok(str, spliter);
do{
output.push_back(p);
p = strtok(NULL, spliter);
}while(p != NULL);
return output;
}
int main()
{
char s[51];
strcpy(s, "I have a cake");
split(s, " ");
}