I have a string which i can break down into tokens but what i want it to do is if it reaches a '//' it breaks out of the loop so no more tokens are added
I have tried using this but it doesn't work
while (p!=NULL)
{
if(p=="//")
{
break;
}
else
{
vec.push_back(p);
p=strtok(NULL," ");
}
}
here is the full code
// strings and c-strings
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
vector<string> SplitString (string aString)
{
vector<string> vec;
char * cstr, *p;
//string str ("Please split this phrase into tokens");
string str = aString;
cstr = new char [str.size()+1];
strcpy (cstr, str.c_str());
// cstr now contains a c-string copy of str
p=strtok (cstr," ");
while (p!=NULL)
{
// i presume a check must be done here
vec.push_back(p);
p=strtok(NULL," ");
}
delete[] cstr;
return vec;
}
int main ()
{
std::vector<std::string> vec = SplitString("Please split this phrase into tokens // this bit needs to be ignored");
for (std::vector<std::string>::size_type a = 0; a < vec.size(); ++a)
{
cout << vec.at(a) << '\n';
}
return 0;
}