File Handling in C++ ...Arrays

A

aejaz

Hey all

I am new to VC++

I want to have my c++ program output to a notepad file

i store my data in arrays and then use cout to output the data in
DOS...as i generate data in the order of 1000's ...i am having a
problem with physically copy pasting the data into notepad

Here is my code...please suggest what changes are necessary
My coding is not really that efficient..please bear with me

Thanks
Aejaz

# include<iostream.h>
# include<conio.h>
# include<math.h>
# include<iomanip.h>

void main()
{
void clrscr();
int i,r,j,m,x;
static Sum[5000][5000];
Sum[1][1]=25000;
Sum[2][1]=35000;

for (j=2;j<=11;j++) // input the data into arrays
for (i=1;i<=pow(2,j);i++)
{
if(i==1)
{
Sum[j] = Sum[j-1] + 25000;
Sum[i+1][j] = Sum[j-1] + 35000;
}
if(i>1)
{
Sum[j] = Sum[r][j-1] + 25000;
r=r+1;
Sum[i+1][j] = Sum[(i+1)/2][j-1] + 35000;
}
i=i+1;
r=2;
}

for (m=2;m<=11;m++) // output the data
{
for (x=1;x<=pow(2,m);x++)
{
for(i=1;i<=2;i++)
{
cout<<x<<m<<setw(10)<<Sum[x][m]<<endl;
}
}
getch();
}

}


my output reads

11 25000
11 25000
12 35000
12 35000

so on..so forth
 
W

WW

aejaz said:
Hey all

I am new to VC++

I want to have my c++ program output to a notepad file

i store my data in arrays and then use cout to output the data in
DOS...as i generate data in the order of 1000's ...i am having a
problem with physically copy pasting the data into notepad
[SNIPped unformatted code]

Why don't you write it into a file? <OT>Or redirect your output to a file
with the > symbol?</OT>
 
K

Kevin Goodsell

aejaz said:
Hey all

I am new to VC++

Here we discuss the C++ language, not VC++ (which is an implementation
of the C++ language - sort of).
I want to have my c++ program output to a notepad file

i store my data in arrays and then use cout to output the data in
DOS...as i generate data in the order of 1000's ...i am having a
problem with physically copy pasting the data into notepad

C++ doesn't have "copy pasting" capabilities. Sounds like an OS issue to me.
Here is my code...please suggest what changes are necessary
My coding is not really that efficient..please bear with me

Thanks
Aejaz

I don't see a C++ question here, but I'll comment on some of the
problems with your code.
# include<iostream.h>
# include<conio.h>
# include<math.h>
# include<iomanip.h>

Of these, only <math.h> is standard (and it's deprecated). <conio.h> has
never existed in C++. The others existed in old, pre-standard C++. Use
<iostream>, <cmath>, and <iomanip> instead.

Also, you'll probably need to add this:

using namespace std;
void main()

main must return int. void is not and never has been an acceptable
return type for main.
{
void clrscr();

Local declaration of a function. That's unusual. Also, I suspect this is
not a function you are writing, in which case you should only declare it
by #including the appropriate header.
int i,r,j,m,x;
static Sum[5000][5000];

There's no type for Sum. This is illegal. Even if it were 'char' this
would be an extremely large array. You may have to check your compiler's
documentation to see if
Sum[1][1]=25000;
Sum[2][1]=35000;

You are aware, aren't you, that C++ arrays use 0-based indexing? Are you
sure you didn't want

Sum[0][0] = 25000;
Sum[1][0] = 35000;

?
for (j=2;j<=11;j++) // input the data into arrays
for (i=1;i<=pow(2,j);i++)
{
if(i==1)
{
Sum[j] = Sum[j-1] + 25000;
Sum[i+1][j] = Sum[j-1] + 35000;
}
if(i>1)
{
Sum[j] = Sum[r][j-1] + 25000;
r=r+1;
Sum[i+1][j] = Sum[(i+1)/2][j-1] + 35000;
}
i=i+1;
r=2;
}


This formating makes to code nearly impossible to understand.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,977
Members
47,556
Latest member
the lucky frog

Latest Threads

Top