Hi all,
I'm trying to make a program that breaks an entered sentence into seperate words, then compares the words to a predefined txt file of words. So far I have the following code, but it just doesnt work for some reason. no errors or anything. It asks for the sentence then closes when you hit enter.
Thanks in advance. I know the code isn't exactly neat, so if you have any suggestions they would be much appreciated.
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
// for the vector option
using namespace std;
string sentence, word;
vector<string> sV;
void findVerb (string word)
{
for(int k = 0; k < sV.size(); k++)
{
string match (sV[k]);
if (match == sV[k])
cout << "the verb in this sentence is" << sV[k] << endl;
}
}
int main()
{
cout << "Enter a sentence: ";
getline(cin, sentence);
// put the sentence into a stream
istringstream instr(sentence);
// the >> operator separates the stream at a whitespace
while (instr >> word)
{
sV.push_back(word);
}
ofstream verbsFile;
verbsFile.open("verbs.txt");
ifstream verbs("verbs.txt");
if (verbs)
{
istream_iterator<string> start(verbs), finish;
for_each(start, finish, findVerb);
} else
cout << "error!" << endl;
cin.sync(); // purge enter
cin.get(); // console wait
return 0;}