Do i still need to append? and do i get the string break. i try cannot only the first line break.
how are you?
I am fine. What about you? I fine too!

the txt file is :

How are you? I am fine. What about you? I fine too!

How are you?
I am fine.
what about you?
i fine too!

//find file and word
cin >> file name;
cin >> searchWord; // cin you

the output display:
how are you?
what about you?
how are you?
what about you?

this is my code somewhere go wrong:
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, 0, line.length()); // join the sentence to a line

found = line.find(wordSearch); // search for cin words
pos = line.find_first_of(".!?");

if ((found!=string::npos) &&( pos!=string::npos))
{

str3 = line.substr (0,pos+1);
str2 = line.substr(pos+1);

cout <<str3<< '\n' << str2 << endl;

}

}
while (!fin.eof())
{


getline(fin,line);


for(int i=0; i < line.length(); i++)
line = tolower(line);


for(int i=0; i < wordSearch.length(); i++)
wordSearch = tolower(wordSearch);


line.append(str1); // join the sentence to a line


found = line.find(wordSearch); // search for cin words
pos = line.find_first_of(".!?");



if (found!=string::npos)
{
str3 = line.substr (0, pos);
str2 = line.substr(pos+1);


cout <<str3<< '\n' << str2 << endl;
}
}

What is your input and expected output?

Please post using code tags ...

How are you? I am fine. What about you? I fine too!

How are you?
I am fine.
what about you? you?
i fine too!

result: How are you?
I am fine.
What about you?
I fine too!
How are you?
I am fine.
what about you?
you?
i fine too!

ignore the top one i reply.
like if u key cin a word you. will display all the sentence with a you

this is the sentence in txt.file:
How are you? I am fine. What about you? I fine too!

who are you?
I am fine.
you are good. you.
i fine too!

output result:
How are you?
What about you?
who are you?
you are good.
you.

Shouldn't be too bad - split the string by '.', '?', and '!'. Then split by ' '. Keep any groups in which 'you' occurs.

what u mean? i cant get what u mean.

this prog i done only can so the first sentence. cant work for the rest of the sentence. how to loop the whole sentence so that every sentence is able to print if i find the word i wan?

while (!fin.eof())
{

getline(fin,line);

for(int i=0; i < line.length(); i++)
line = tolower(line);

for(int i=0; i < wordSearch.length(); i++)
wordSearch = tolower(wordSearch);

line.append(str1); // join the sentence to a line

found = line.find(wordSearch); // search for cin words
pos = line.find_first_of(".!?");


if (found!=string::npos)
{
str3 = line.substr (0, pos);
str2 = line.substr(pos+1);

cout <<str3<< '\n' << str2 << endl;
}
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.