Jump to content
  • Advertisement
Sign in to follow this  

[stl] failing to read file o.0

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

okay ive got the following chunk of code:
std::ifstream in(args[5], ios::binary);
	//in.seekg (0, ios::beg);
	if (!in.is_open())
		cout << "Failed to open " << args[5] << endl;
		return 0;
	char buffer[256];
	int bytes = in.readsome(buffer, 256);

so it manages to open the file, which is a file with some text in it. Now, in.readsome returns 0 like wtf?!

Share this post

Link to post
Share on other sites
std::basic_ifstream::readsome reads from a stream's stream buffer only, that means what's been buffered into memory and available already so in this case since you're calling it on a freshly opened file input stream obviously the buffer is empty hence returns zero bytes read from the buffer. Use std::basic_ifstream::read for the initialize read at the very least.

Another thing to realize is that these operations are unformatted I/O, are you sure you really want to do this for a text file rather than formatted I/O.

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.

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!