Filestreaming Error

Aug 13, 2010 at 4:17am
Hey everyone, I was wondering if someone could take a quick look at my code because I have an error somewhere and I'm not sure exactly whats wrong with my code, any help would be greatly appreciated thanks!

btw, I'm trying to read two lines from a text file and write "GO" into file just so you don't get confused.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int main()
{
	ifstream rideIn;
	char cometLine[6];
	char ufoLine[6];
	int cometSum,ufoSum;

	rideIn.open("file.txt");

	if(rideIn.is_open())
	{
		rideIn.getline(cometLine,256);
		cometSum = (lineTotal(cometLine,1,0)) % 47;
		rideIn.getline(ufoLine,256);
		ufoSum = (lineTotal(cometLine,1,0)) % 47;
		rideIn.close();
	}

	ofstream rideOut;
	rideOut.open("file.txt",ios::ate);
	if(cometSum == ufoSum)
		rideOut.write("GO",256);
	rideOut.close();
	
	system("Pause");
	return 0;
};
Last edited on Aug 13, 2010 at 4:20am
Aug 13, 2010 at 7:36am
What is the error youre getting?
Aug 13, 2010 at 10:24am
Possible sources of error
1
2
char cometLine[6];
rideIn.getline(cometLine,256);
cometLine can hold 5 characters but you're attempting to extract 255 (same for ufoLine)

rideOut.write("GO",256); Don't sure what will happen, because GO has 2 letters, no 256.
Why don't use rideOut << "GO" instead?

rideOut.open("file.txt",ios::ate); This could fail too. (i. e. don't have writing permission)
Aug 13, 2010 at 12:49pm
okay cool thanks I'll try that out, i don't quite get the file streaming functions yet, thanks alot for the help ne555!
Aug 13, 2010 at 2:00pm
Yea it worked thanks alot for help!
Topic archived. No new replies allowed.