I am writing a particle tracker in C++ which releases a particle in a numerical flow field and then integrates in time to calculate the new position of the particle.
This is done for as many particles as time allows (hopefully millions) for approximately 10k timesteps per particle. During the simulation I generate a double array1[10k][10] and int array2[10k][4] which represent the 14 characteristics of each particle at each timestep.
My question is how to write such a 'matrix' to a notepad++ readable .txt file (for the purpose of post-processing). Both arrays are to be merged in the file such that a [10k][14] matrix is formed.
Personally I have only had experience with fprintf but Visual Studio appears to have some security issues with that function. Other functions I have seen are streams (more secure I suppose) and fwrite.
Could someone enlighten what the advantages and disadvantages are of the similar functions? And possibly what the better choice is for my problem (if there is one).
Kind regards,
EJG
Newer Microsoft compilers give you various "security" warnings if you do not define _CRT_SECURE_NO_WARNINGS. See here and here
The _s
versions it will suggest using instead are microsoft specific, so if you ever wanted to compile your code for another platform you would need to re-write.
There are other ways to write to files in C++. You could consider using a C++ std::ofstream
instead.
Or, you can just write to std::cout
and stream the program output to a file
myprogram.exe > output.txt