0

suppose I have a string

string text = "There are       many empty   space   and  tabs inside      ";

The empty space in this string might be \t or " ", and uncertain how many spaces or tabs between two tokens. How can I get tokens from that string? Which is a better method, 'strtok' or 'substring'?

user3083108
  • 80
  • 1
  • 5

1 Answers1

0

Use an std::istringstream:

std::istringstream in (text);
std::vector<std::string> tokens;

for (std::string temp; in >> temp; )
    tokens.push_back(temp);
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182