tags:

views:

96

answers:

2

Hi to all. I have text file with some text information and i need to split this text at spaces and all word push into List.

I make so:

 QStringList list = line.split(" ");

  for (int i = 0; i < list.count(); i++){

      table.push_back(list[i]);
      this->ui->textEdit->setText(list[i]);
  }

In line i have my text. But when i test this code i get all text, but not by the word.

Thank you.

+4  A: 

Try it with:

line.split(QRegExp("\\s"));
NomeN
Thnak you it's work!
shk
+1  A: 

istream will already split according to whitespace. So an easy way to do this is

std::istream & txttosplit=X;///X is istringstream, or ifstream, or cin, etc
std::vector<std::string> words;
std::copy(std::istream_iterator<std::string>(txttosplit),
          std::istream_iterator<std::string>(),
          std::back_inserter(words));
Lance Diduck
+1: But OS asked for a list not a vector.
Martin York