Jump to content
  • Advertisement
Sign in to follow this  
c0uchm0nster

Trouble opening a file (ifstream/wfopen)

This topic is 4562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.)

Share this post


Link to post
Share on other sites
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;


#include ".\lecture.h"

CLecture::CLecture(void)
{
m_bPeutLire = false;
}

CLecture::~CLecture(void)
{
}

//Open the file
void 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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!