i cant figure where i go wrong. the output is wrong. anyone out there can find out where my mistake at? really need yr help. thanks.
My txt file the sentence are :
How are you? We think in generalities, but we live in details. what about you?
Who are you?
Have a dog.
i got. Do you have a dog?
i have dog.
- cin >> you
output is :
how are you?
We think in generalities, but we live in details. what about // error should display what about
you ?
Who are you?
i got. // error
Do you have a dog?
- cin >> dog
output is:
have a dog.
i got. do you have a dog? // error "i got" not to be display
i have dog.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int MAX_FILE = 50;
int main()
{
string line, str1, str2, str3;
string wordSearch;
size_t found ;
size_t pos=0, pos1=0 ;
char fileName[MAX_FILE];
cout <<"Enter the filename:";
cin >> fileName;
fflush(stdin);
cout << endl;
ifstream fin;
fin.open (fileName);
if(!fin.good())
{
cerr << "File not found" << endl;
system("pause");
exit(1);
}
cout <<"Word Search:";
cin >> wordSearch;
fflush(stdin);
cout << endl;
while (!fin.eof())
{
getline(fin,line);
for(int i=0; i < line.length(); i++)
line[i] = tolower(line[i]);
for(int i=0; i < wordSearch.length(); i++)
wordSearch[i] = tolower(wordSearch[i]);
line.append(str1); // join the sentence to a line
found = line.find(wordSearch); // search for cin words
if(found!= string:: npos)
{
pos = line.find_first_of(".!?", pos+1);
pos1= line.find_first_of(".!?",pos+1);
str2= line.substr(0,pos+1);
str3 = line.substr(pos+1, pos1+1);
cout << str2 << endl << str3 <<endl;
}
}
fin.close();
return 0;
}
<snip plug]