Please help me to translate this code from c to c++

#include <stdio.h>
#include <conio.h>

void main()
{
int n,i,j,a[20][20],ok=1,grade=0,aux=0;ok=1;
FILE *f=fopen("c:\graph.txt","r");
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
  for(j=1;j<=n;j++)
     fscanf(f,"%d",&a[i][j]);
fclose(f);

for(i=1;i<=n;i++)
  if(a[1][i]==1) grade++;

for(i=1;i<=n;i++)
 {
  for(j=1;j<=n;j++)
   if(a[i][j]==1) aux++;
  if(aux!=grade) ok=0;
  aux=0;
   }     
if(ok==0) printf("graph is not regular.");
 else printf("graph is regular.");
getch();
clrscr();
}

Looks like it compiles in C++, grats, you're done.

Yes, but i still need to translate it to C++.
I'm not into C++ and here I all know is replacing printf with cout and FILE *f=ofpen to ifstream.

That, and replace "void main" with "int main" and use cin instead of fscanf. There's nothing else different between C and C++ in that program.

Yes, but i still need to translate it to C++.

Since it's already valid C++ (assuming compiler support for non-portable stuff), you'll need to define what you mean by "C++".

fscanf() -> cin
fprintf() -> cout
void main(...) -> int main(...)

IE, what Ancient Dragon said. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.