Jump to content
  • Advertisement
Sign in to follow this  

Basic File IO

This topic is 4148 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'm working on some basic file IO. I can output to files just fine, but I can't seem to input to files. I have a file called ints.doc. It has the numbers 5, 6, 7, 8 in it, except without commas and with spaces. Whenever I read in the values I get random values, like the variables aren't being filled with anything. I'm sure I'm making some small mistake, but I just can't figure it out. In case it matters, I'm on a mac using Xcode 2.0. Thanks
#include <iostream>
#include <fstream>
using namespace std;

int main () {
	ifstream inputStream;
	int n1, n2, n3, n4;
		cout << "Failed to open file.";
		return -1;
	inputStream >> n1 >> n2 >> n3 >> n4;
	cout << n1 << " " << n2 << " " << n3 << " " << n4;
	return 0; 

Share this post

Link to post
Share on other sites
Do you have office installed on your box?
Is this .doc document a Microsoft Office Document?

If it is then you are reading the header of the document (several file types have headers)

Try using a simple .txt file, your code works fine on Visual Studio 2005 on a windows box.

If you are trying to read an office document then basic file IO is not going to give you want you want without parsing/processing the internal format of the document.

Share this post

Link to post
Share on other sites

After opening the file in a basic text editor, I found out that it had a monster header file that was killing my input. After removing the header, it works perfectly.


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!