jeudi 2 avril 2015

ifstream is not working, not reading files

I'm trying to get this filereader to work, but i'm having trouble with it opening/finding the files, here is the code:



std::string FileReader::getInput(std::string name)
{

std::string text;
std::ifstream ifs;
ifs.open(name.c_str());
if(ifs.is_open())
{
ifs>>text;

}
else
{
std::cout << "unable to open" << std::endl;
}

ifs.close();
return text;
}


It just doesn't seem to find the file, regardless of the input, even thought I am absolutely positive it's in the right place. I've also tried replacing the name.c_str() to this: "C:\foo.txt", and putting the file there, no dice. I'm wondering if any of you could point me to the right direction.. thanks!


Aucun commentaire:

Enregistrer un commentaire