-1

I want to get this character in 3 part: ab,83,and de. But i don't know how to get the char between the spaces and 2 char after the last space. Please tell me how to do it. Thank you

void main()
{
    char input[12]="ab 83 de";
    char *p;
    p = strtok(input,"  ");

      while (p != NULL)
      {
        printf ("%s\n",p);
        p = strtok (NULL, "  ");
      }
}
Nicky Apriliani
  • 321
  • 4
  • 25

1 Answers1

1

You can use std::istringstream with operator>>:

istringstream iss("ab 83 de");
string str;
while (iss >> str) {
    // process with str
}

LIVE

songyuanyao
  • 169,198
  • 16
  • 310
  • 405