There is no matching constructor to initialize 'ifstream'

I get an error in the following code, it worked fine in visual studio, but as soon as I moved it to Xcode, which uses gcc to compile, get this error. There is no corresponding constructor to initialize "ifstream". I looked at adding this as a link, not a copy offered on this site, but she still came up with an error.

void getAndSetTextData::GetBannedList(string fileName)
{
    bannedWordCount = 0;
    ifstream inFile(fileName);
    while(inFile >> currentWord)
    {
        bannedWords.push_back(currentWord);
        bannedWords[bannedWordCount++] = currentWord;
    }
    inFile.close();
}  

Any help would be appreciated.

+5
source share
2 answers

ifstreamthe constructor accepts const char*as a file name (previously C ++ 11):

ifstream inFile(fileName.c_str());

In C ++ 11, an additional constructor is added, which takes const std::string&as a file name.

: string fileName const string& fileName, fileName.

+11

, . , , ..

ifstream inFile(fileName);
if( ! inFile )
   return;
while(inFile >> currentWord)

, fstream?

0

All Articles