spliting words

how can i display words form a long sentence.
example :(lets assume that if u find two spaces that is word)
INPUT:the Indian school boys are very good compare to other countries.
OUTPUT: the Indian
school boys
are
very
good
compare to
other countries
i am solving these way but it takes only one space to divide a word.
#include <string>
#include <vector>
#include <fstream>
#include <iostream>

int main()
{
std::vector <std::string> words;
std::string str;
std::cout << "Read from a file!" << std::endl;

std::ifstream fin("thisfile.txt");
while (fin >> str)
{
words.push_back(str);
}
fin.close();

for (int i = 0; i < words.size(); ++i)
std::cout << words.at(i) << std::endl;

return 0;
}
Last edited on
yes, the stream does not take the number of delimiter into account.

if you want to achieve that, there're several way.

You might read it char by char and if you detect a space push back the word and clear it.
Topic archived. No new replies allowed.