remove grammer from string

Hello i'm making a program where i have to search through a txt file and find the a word but the word should be found even if the word is "isn't" and the user entered "isnt"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cout<<"Please provide a filename: ";
	cin>>userFile;
	fstream doc(userFile.c_str());
	if (doc)
		{
		while (!doc.eof())
			{
			doc>>tmp;
			doc.erase (remove (doc.begin(), doc.end(), ' '), doc.end());
            doc.erase (remove (doc.begin(), doc.end(), ','), doc.end());
            doc.erase (remove (doc.begin(), doc.end(), '.'), doc.end());
			b.insert(b.getRoot(),tmp);					
			//doc>>tmp;
			}
		doc.close();
		doc.clear();
		break;
		}
	else
		cerr<<"File Not Found!"<<endl;


the erase feature doesnt work for me although i've seen it before i'm not sure why it doesnt work now. also this should work to find "end." when user enters end. could it be that this works for only entire lines and not individual words?

i get the errors:
h6.cpp:80:8: error: ‘std::fstream’ has no member named ‘erase’
h6.cpp:80:27: error: ‘std::fstream’ has no member named ‘begin’
h6.cpp:80:44: error: ‘std::ios_base::end’ cannot be used as a function
h6.cpp:80:61: error: ‘std::ios_base::end’ cannot be used as a function
h6.cpp:81:17: error: ‘std::fstream’ has no member named ‘erase’
h6.cpp:81:36: error: ‘std::fstream’ has no member named ‘begin’
h6.cpp:81:53: error: ‘std::ios_base::end’ cannot be used as a function
h6.cpp:81:70: error: ‘std::ios_base::end’ cannot be used as a function
h6.cpp:82:17: error: ‘std::fstream’ has no member named ‘erase’
h6.cpp:82:36: error: ‘std::fstream’ has no member named ‘begin’
h6.cpp:82:53: error: ‘std::ios_base::end’ cannot be used as a function
h6.cpp:82:70: error: ‘std::ios_base::end’ cannot be used as a function
It seems Erase is a string method, not a filestream method. That could be one of your errors.

http://www.cplusplus.com/reference/string/string/erase/
Read the file (perhaps line by line) into a std::string. erase() will work on the string.

1
2
3
4
5
6
std::string line ;
while( std::getline( doc, line ) )
{
     // process the line
     // ...
}

fstream class does not have erase method.
fstream class is not container class so it does not have iterators.
string class can't be "cin'ed" cos it does not provide operator>>
You are using enums as if they where methods or iterators??

You'll have to lookup into IOstream reference to refresh you knowledge.
http://www.cplusplus.com/doc/
yeah your right i got all that to work but i've encountered another problem. i cannot use these methods to remove the " ' " symbol because it will say that their is a missing ' .

tmp.erase (remove (tmp.begin(), tmp.end(), '''), tmp.end());

h6.cpp:83:56: error: empty character constant
h6.cpp:83:58: warning: missing terminating ' character [enabled by default]
h6.cpp:83:13: error: missing terminating ' character
"\'"
ok it worked thank you all
'\''

Or, instead of special casing for each punctuation character:
1
2
auto punct = [] ( int i ) { return std::ispunct(i) ; } ;
line.erase( std::remove_if( line.begin(), line.end(), punct  ), line.end() ) ;

Topic archived. No new replies allowed.