Writing to a file

I will try to explain how to do this here on different platforms. Unix and Windows have different ways of expressing file paths so you need to make sure you use the correct path depending on the machine that you are using.

Open up a new project and copy and paste the following code into your main file - file write code . Now edit the line containing output.open("...");. The string containing the quotes must give a valid path to the directory that you want to open the file in. If you do not specify a path, e.g.

output.open("test.csv");

then the file will be saved in the directory in which the program is run. You can try it this way and see if you can find the file!!! By valid path, we mean that the directory must exist, i.e. that you have already created it. So open up My Documents (or your home directory in unix) and create a new folder called "Data". The path to that directory should look something like:

So now enter (inside quotes) the full path to the directory and a filename to write to. There are some examples that I might use in the code. Obviously you will have to substitute your name or username.

Now run the program. If you see the text File write successful everything should have worked. Now try plotting the data file using:



Other HowTos...

Getting Started

Including NAG dll

Optimising your programs


Return to Homepage