Trouble opening a file (ifstream/wfopen)
Hi,
I'm trying to open a file in a unicode program.
I've tried many things, such as assigning wfopen to an ifstream, using _wfopen_s to assign to a FILE and then pointing the ifstream at that FILE, using the .open function of an ifstream, etc etc...
They always report 0 errors, but they always have a NULL pointer... .is_open() reports that the file is open as well...
Any help would be greatly appreciated.
have you tried a wifstream?
it looks like it solves what you are trying to do.
It works like ifstream, but opens in unicode.
You should be able to
wifstream myfile;
myfile.open ( ... );
and have it work just fine.
(never played with it myself, but MSDN pulled this up after a quick search.
It should point you in a direction that might work.)
it looks like it solves what you are trying to do.
It works like ifstream, but opens in unicode.
You should be able to
wifstream myfile;
myfile.open ( ... );
and have it work just fine.
(never played with it myself, but MSDN pulled this up after a quick search.
It should point you in a direction that might work.)
Alright, i sugest you to use fstream. It's a somewhat easy library in my opinion.
To open a file you need first an object type ifstream.
ifstream m_oFichierGeneration;
this is my class that i use whenever i need to read a file and it's working pretty well. If you have any question feel free to ask.
To open a file you need first an object type ifstream.
ifstream m_oFichierGeneration;
#include ".\lecture.h"CLecture::CLecture(void){ m_bPeutLire = false;}CLecture::~CLecture(void){}//Open the filevoid CLecture::Ouvrir_Fichier(string sNomFichier) // the string is the name of the file being pass as parameter{ m_oFichierGeneration.open(sNomFichier.c_str(), ios::in ); if (!m_oFichierGeneration.fail()) //if it doens't fail to open { SetPeutLire(true); // Set m_bPeutLire = true } else { m_oFichierGeneration.clear(); // Dont forget to clear if it's fail SetPeutLire(false); }}bool CLecture::PeutEncoreLire(){ return !m_oFichierGeneration.eof(); // If not at end of file}int CLecture::Lire_Fichier(int iLecture){ m_oFichierGeneration >> iLecture; //Read an int return iLecture;}char CLecture::Lire_Fichier(char cEtat){ m_oFichierGeneration >> cEtat; //Read a char return cEtat;}void CLecture::SetPeutLire(bool bPeutLire){ m_bPeutLire = bPeutLire;}bool CLecture::GetPeutLire(){ return m_bPeutLire;}
this is my class that i use whenever i need to read a file and it's working pretty well. If you have any question feel free to ask.
kulseran - thanks, the files themselves aren't actually stored in unicode - they're normal ascii. I was just mentioning that my program was unicode because that seems to affect how you use every single other function under the sun ;)
deathwearer - that works great. I was actually pretty close but I guess I got confused since, even after the file loads correctly, the ifstream still points to null in the ms vc++ 2k5 debugger.
thanks again
deathwearer - that works great. I was actually pretty close but I guess I got confused since, even after the file loads correctly, the ifstream still points to null in the ms vc++ 2k5 debugger.
thanks again
Hmmm kinda weird. I don't know why, but oh well, if it's working, let's not hurt our head for nothing ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement