Thursday, July 30, 2009

I am new to C++ I want code to create a text listing of integers that can be sent to others.?

I am good at writing macros in Excel to solve problems in number theory but frustrated by the inability to work with large numbers in Excel. I have progressed through 4 chapters in Visual C++ 6.0 but am a little frustrated at my pace.

I am new to C++ I want code to create a text listing of integers that can be sent to others.?
If you are trying to export the list to a text file, you'll have to create an fstream object via:





#include fstream


//include file within the preprocessor directives





//then in the code body declare the ofstream object (output fileStream object)


ofstream dataOut;


dataOut.open("Filename.txt");





Create your 1-D array/list:


int J=1000; //upper limit integer, highest value int you want


int nums[J] // integers up to 1000


for(int i=0; i%26lt;J; i++){


nums[i]=i;


}





Then when you want to export, simply use dataOut in place of cout:





for(int j=0; j%26lt;J; j++){


dataOut%26lt;%26lt;nums[j]%26lt;%26lt;endl;


}





dataOut.close();


No comments:

Post a Comment