Data From C++ GUI to Excel/Notepad, Application Trouble

“Hi,
I need to get data from a C++ application to a spread sheet or notepad file, has anyone any idea how to do this. I have access to programme source code but not sure where to start.”

Are you using Visual C++? If yes, then download and install Visual C++ 2005 Express Edition form microsoft.com.

A “notepad file” would be easier to output to than a spread sheet, which would require you to research the file-format.

To output to a file from a C++ program, you have a few choices.

  1. The program can output all of the data you need to a command line, and then when you run the program run it as:

your_program.exe > file_with_data.txt

The “>” tells the command line to take all of the text that was outputted to stdout (which is what cout and printf do) and put it into the file following the “>” sign, in this case “file_with_data.txt”

  1. There is a standard library for outputting to files for C++ from within the program. It’s called ‘fstream’, so you would put “#include <fstream>” at the beginning of your program.

To use this, you would need to make an fstream object at the beginning of your program, and then use it like “cout” to output data. Here’s an example:


fstream file_output; // create an 'fstream' object
file_output.open("my_filename.txt"); // open the file 'my_filename.txt'
//whenever you want to output data:
file_output << "This goes into the file";
//and at the end to close the file:
file_output.close();

You could google ‘fstream’ or ‘file i/o tutorial’ for more/better help.

Hope that was clear, good luck :stuck_out_tongue:

If you want to output to a spreadsheet, look into CSV. Excel and most other spreadsheet tools can read it automatically.

It’s basically just like writing to a text file, but inserting commas and carriage returns to denote rows/columns.