However it seems to work with character arrays, not a string object. Which is why I capitalized and bolded the word "string".
So would it still work on a string? If so HOW? lol :P
Also I will eventually need to compare the extracted data (for example "joe" with another string. Sooo it would be nice if the extracted data was a string, but if it's a char array, then how do I compare a char array with a string.
I would use std::istringstream for this task. For example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <sstream>
#include <string>
int main()
{
std::string s = "hello - my name is - joe";
std::istringstream is( s );
while ( is )
{
std::string t;
std::getline( is, t, '-' );
std::cout << t << std::endl;
}
}
The program output is
hello
my name is
joe
You can also use a string algorithm in particular find. For example