Im using vectors in some functions and I would like to print the content of the vectors in an Excel file. Can anybody help? I have vectors of 1200 items and would like that each item be stored in a different cell in my Excel file. Is that possible?
Probably the fastest way is to just output the contents with something like std::cout <<vector[i]<<std::endl; and redirect the output to a file by calling the program with something like program>output.txt
Then you can just copy the contents to the spreadsheet and they'll be in a single column.
You need to store the output of your program in a file (that can be a .txt or a .csv file). This can be done using ofstream or, if you're using windows, with command line (I would recommend the last one, because its simple. When you would run a normal program like this: "myProgram.exe", type "myProgram.exe > myFile.txt" instead).
After your output is in a file, you can import it in excel. Open excel, and use Data>Import. Select your file and follow the wizard.
Yes, maybe it is, at least when you know what it is and how to use it. But like OP said: he's a beginner, so i would stay away from filestreams. Aldo, you may be right. It isnt hard to understand.
Now, is there a way to create/open those files with a variable in the name? What the program does right now is that it creates "file.xls" and fills it with the required data. If I were to put that code in a loop so that it creates a new file with a different filename instead of overwriting that file.xls (or instead of adding the data at the end "ios::app"), how would I do that?
To get around what? There is no problem using iostream (not .h) and using namespace std;, and there isnt much difference between using usingnamespace std; and std:: when you dont have several namespaces.
Besides that, I dont believe that is the problem, aldo I agree he should include <iostream>, not <iostream.h> (->older version)
Um... No...
The standard is all C++ headers are included without extension. You must have meant "some compilers are shitty and let you include non-standard headers without so much as a warning. And worse still, they reinterpret your inclusions based on your declarations".
The reason the're picky is becaue the libarys with .h are different then the ones without: first you got <iostream.h>, then there was made a newer version wich was called simply <iostream> so people wood be able to see wich libary is used.
I never use the .h version, so I dont know or that gives strange results when using namespace std; But when you use <iostream>, there is no need to avoid using namespace std;