fstream problem

hi guys, there something here thats freakin me out since i cant find out whats wrong with the code. im writing a CFD code in Xcode on my Macbook pro in C++ and i need the code to output some of its results to certain text files for which im using the fstream class. the following code is the part where my first problem lies:

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
if ((t <= 0.4 + dt/5.0) && (t>=0.4 - dt/5.0)){
	std::cout << endl;
	std::cout << "t: " << t << endl;
	std::cout << "x			u" << endl;
	std::cout << endl;
	result4.open ("/Users/bamdadhosseini/Desktop/nonhomogenous/04.dat " , fstream::in | fstream::out | fstream::ate);
	for (int i=0; i < (nodes); i++){
	        std::cout << dx*i << " " << u_deriv[i] << endl;
		result4 << dx*i << "	"<< u_deriv[i]<< endl;
	};
	result4.close();
};
		
if ((t <= 0.6 + dt/5.0) && (t>=0.6 - dt/5.0)){
	std::cout << endl;
	std::cout << "t: " << t << endl;
	std::cout << "x			u" << endl;
	std::cout << endl;
	result4.open ("/Users/bamdadhosseini/Desktop/nonhomogenous/06.dat " ,   fstream::in | fstream::out | fstream::ate);
	for (int i=0; i < (nodes); i++){
		std::cout <<  dx*i << " " << u_deriv[i] << endl;
		result4 << dx*i << "	"<< u_deriv[i]<< endl;
	};
result4.close();
};

i also create the text files using another function with the ::trunc option.
now the problem is that the code will output my results for 06.dat but it doesnt output anything into the 04.dat file. but i cant understand this since i have just copied and pasted the code here for each step. my other problem is that using this method i suppose i should get plain text. but when i try to input these files to Gnuplot i get an error telling me that it cannot read the file. but it reads it when i copy the text inside these files and paste them into another plain text file created by text edit :| why is this happening? i cant figure out where im goin wrong.
I am not sure how much of a role this plays in the problem, but for the names of the files you are opening, it looks like you have an unwanted extra space after the .dat and before the closing quotation mark. The first thing I would do is remove that space.

~psault
Topic archived. No new replies allowed.