output to Excel
| Cbas (11) | |||
| I've been reading all the information on outputting files, however, I still cant output my array to excel. Any ideas? Please The array call it A is A[320] with float variables. I need to ouput these to excel so i can plot a graph Thanks | |||
| Duoas (801) | |||||
| The simplest way would be to make a CSV file, which is just a plain-text file with each row on its own line, and each column separated by commas. Excel can read that. Example (as a bonus you'll get to see a template function at work):
An example of using it:
The trick with the a[0] is that it passes the address of the first row of the array to the function, which is an array of int (what the function takes). This relies on the fact that an array is linearly mapped (always true for every C and C++ --at least by standard). The nice thing about a template function is that you can make arrays of int, std::string, float, char, struct, class, etc. so long as the ostream << operator is overloaded to work with it. That's true for all simple types (int, string, etc.), but not for structs and classes. You can use the same function with these different types in the same program. Mentally (or, if you just don't want to use a template function, actually) you can replace the typename t_data with whatever the base type of your array is. Anyway, this is probably waaay more info than you wanted, but I hope you find it useful and instructive and entertaining. :-) | |||||
| Duoas (801) | |||
| Crud. I just re-read your first post and realized that you are trying to output a one-dimensional array... The word 'Excel' put my brain into automatic and I thought 2D. The concept remains the same. Just get rid of all that "row" stuff and change a[0] to a and you'll do fine. | |||
This topic is archived - New replies not allowed.
