Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Zorbfish

FileReader

This topic is 5892 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

I have to write this for class in the next few weeks so I thought I''d do it before my professor assigned it.
  
class CFileSystem{
public:
	fstream m_fFile;
	char    m_cBuffer[8];
	CFileSystem(char cName[]);
	~CFileSystem();
	void write_log_header();
	void line_break();
	void write(char cName[]);
	void close();
};
  
This is a small filesystem (very basic) which writes out to a text file. Then whenever a user inputs a line it writes to the text file as: HH:MM:SS: message My first problem was with the constructor:
  
CFileSystem::CFileSystem(char cName[]){

	m_fFile.open(cName,sizeof(cName),1);
};
  
So when I contruct the class like so, CFileSystem File("input.txt"), nothing happens. Im assuming this is because when I call sizeof() in the constructor it doesnt know the size of the char array cName. Anyone wanna comment? So far the only solution I can come to is adding another param to the constructor, int nSize, and manually setting the size.

Share this post


Link to post
Share on other sites
Advertisement
Try using strlen() instead of sizeof().
Also i''d prefer to pass the string as a pointer simply like this: CFileSystem::CFileSystem(char *cName);

But i dont know much about c++ streams so i dont know if this helps...

--Helicon56,

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!