Extracing words that start with ‘#’ from a string into a stringstream- C++

  c++, istringstream, string

I am trying to write a program that will return words that start with the symbol # from a string.
For example:
A string such as "I like #tacos and #pizza" would return: #tacos #pizza

This is my current code:

int main(void){
    string myString = "I like #tacos and #pizza";
    std::istringstream iss(myString);
    while(iss >> myString){
        int i = 0;
        if(myString[i] == '#'){
            iss >> myString;
        }
        i++;
    }
    std::cout << myString;
}

However, this only returns one word that starts with a hashtag. Any help as to what I can change in the code?

Source: Windows Questions C++

LEAVE A COMMENT