I am creating a program that reads an input file of text only and creates a vector of the words in that input file. The program I have now only prompts the user for the input file name and then stops running after that. My text file has only 3 words in it for a test, but by the end of the program I hope to be able to read large text files such as stories.
My code:
#include<string>
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
int main(){
string filename; //name of text file
string wordsFromFile; //the words gathered from the text file
cout << "Please enter the name of your text file" << endl;
cin >> filename;
ifstream fin(filename.c_str());
fin >> wordsFromFile;
while(fin >> wordsFromFile)
{
fin >> wordsFromFile;
vector<string>word;
for(int i=0; i<=word.size(); i++) {
word.push_back(wordsFromFile);
cout << word[i];}
}
fin.close();
return 0;
}