Opening a file Error using List<string>


My problem is that I get an 2 errors that says:

In constructor 'Dictionary::Dictionary(const string&)':

[Error] could not convert 'iFile.std::basic_ifstream<_CharT, _Traits>::open<char, std::char_traits<char> >((& filename)->std::basic_string<_CharT, _Traits, _Alloc>::c_str<char, std::char_traits<char>, std::allocator<char> >(), (std::_Ios_Openmode)8u)' from 'void' to 'bool'

[Error] in argument to unary !

I am not sure what to do with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Lexicon::Lexicon(const string& filename)
{
	//lexicon= list<string>();
	//Opens the file
	ifstream iFile;
	if(!iFile.open(filename.c_str()))
	{
		cerr<< "at Lexicon::Lexicon(): File couldn't oepn. \n";
		return;
	}
	
	string words;
	//Reads all word from file
	while (iFile >> words)
	{
		addWord(words);
	}
} 
open doesn't return a value, so testing the value it doesn't return doesn't make much sense.

1
2
3
4
    std::ifstream iFile(filename);
    if (!iFile.is_open())
    {
        // ...  
Topic archived. No new replies allowed.