Break a file into whitespace-separated words - C++ File Stream

C++ examples for File Stream:File Operation

Description

Break a file into whitespace-separated words

Demo Code

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {//from   w ww.  j a v a 2  s .  co m
   vector<string> words;
   ifstream in("main.cpp");
   string word;
   while(in >> word)
      words.push_back(word);
   for(int i = 0; i < words.size(); i++)
      cout << words[i] << endl;
}

Result


Related Tutorials