1

I was solving attribute parser on hackerRank but I am stuck with delimiter. I want to grab an element from ("any thing"), in this case it will give me (any thing), but when I do this:

while (getline(ob, item, '""')) {//but its be true when i put single one ('"')
        std::cout << item << "\n";
    }

It gives me this error:

E0304 no instance of "getline" matches the argument list

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

1

As @RetiredNinja said, you can use '\"' as the delimiter. The code may look like this:

#include <iostream>
#include <string>


int main()
{
    std::string str;
    while (std::getline(std::cin, str, '\"'))
        if (!str.empty() && str[0] != '(' && str[0] != ')')
            std::cout << '(' << str << ")\n";
}

You can change the code based on the rules of the problem. Note that the delimiter would give you "(" first, then the actual word and so on. So you'd have to filter the values you're not interested in.

StackExchange123
  • 1,871
  • 9
  • 24