Blacksheep, thanks for your reply. As seen above, I followed your suggestion but my program still does not write to a_file. What am I doing wrong? Can you please give me an example? Thanks. . . . therry
I compiled your program, and it worked perfectly, after I created the 'tcmi' and 'RawData' directories in the root of the C drive, since that is where the program is looking for it.
whitenite1, thanks for your reply. What would stop it from working on my computer? I use Windows 7 (x64) and Microsoft visual studio pro 2010. It works perfectly on screen, but it will not write to the file.
Thanks. . . .therry
Not sure, since I also use Windows 7 on a x64, and I use Visual Studio 2012 Express. The only thing that comes to mind is that one of the two directories, have a different spelling than what you're looking for in the program. Try removing "C:\\tmci\\RawData\\Sqr_root.txt" and replace it with just "Sqr_root.txt" instead. Then check the directory the <name of your program>.cpp is in, and see if the text file is in there. If it is, then the location you were checking originally, must be wrong. Hope this helps..
whitenite1, Thanks for your help. I've tried everything that I could think of. Since the search for the file is outside of the for loop, it has no effect on the program. I'm beginning to suspect the line a_file << x << " " << z ; I don't know if it is really correct. . . or is there another way to write to a file? I wonder why the program does not complain when I build it. . . .therry
// Write File.cpp : main project file.
#include <iostream>
#include <math.h>
#include <fstream>
usingnamespace std;
int main()
{
longdouble x = 0.0;
longdouble y = 0.01;
longdouble z = 0.0;
ofstream a_file( "C:\\tmci\\RawData\\Sqr_root.txt"); // Or try changing to
// ofstream a_file( "C:\\Temp\\Sqr_root.txt");, then check Temp dir for result
for (int i = 0; i < 49; i++ )
{
x = (x + y);
cout << x ;
z = (x * x);
cout << " " << z << endl;
a_file << x << " " << z << endl; // Added a newline, so each set of numbers is on a separate line
}
a_file.close(); // Probably not needed, but still good idea to close files
system ("Pause");
return 0;
}
whitenite1, thanks again for your replies. I tried the above code, it reacts the same as mine. Both works well on screen, but both will not write to a_file regardless of the directory that Sqr_root.txt is in. If the above code writes to a_file on your computer, can you please email me a copy of "Sqr_root.txt" file so I can check it against my computer? Send it to <therry1@yahoo.com>. I now question my computer installation of my compiler. . . thanks again,. . . . therry