I am trying to read each word from a file and put it in a pointer then send it to a vector.
Here is what I have so far. I am having a hard time sending the data to a function where I will add it to a vector.
Here is what I have so far. Right now the output is showing the last word of the file spelt out with one letter per line. It should be showing all the words from the text file with one word per line. (I will be counting the words later right now I am just trying to get this part done.) Thanks for your help.
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void WordFunction(string *pstr);
int main()
{
ifstream file;
string word;
file.open("word.txt");
while (!file.eof())
{
file >> word;
WordFunction(&word);
}
file.close();
for (int i=0; i < word.size(); i++)
{
cout << word[i] << endl;
}
system ("pause");
return 0;
}
void WordFunction(string *pstr)
{
vector<string *> words;
words.push_back(pstr);
}