got a question. y i unable to break the line when it reach ".,?" ? when i compile only the first line break.how i able to break the second one? i try alot of method is still unable to work. anyone out there Pls help me out so that i able so solve the problem.Thanks.
after compile:
We think in generalities,
but we live in details. How are u?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str="We think in generalities, but we live in details. How are u?";
string str2, str3;
size_t pos;
if ( pos = str.find_first_of(".,?"))
{
str3= str.substr(0,pos+1);
str3 is set to the first part of the string up to the comma and str2 is set to the rest of the string.
You have to repeat the find_first_of() and substr() using str2 to form two more strings
"but ... details. " and "How are u?".
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