c into c++

This is a discussion on c into c++ within the C++ Programming forums, part of the General Programming Boards category; this is not in c++ format is it? can someone help me translate this to c++.... Code: #include<stdio.h> #include<conio.h> int ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    31

    Question c into c++

    this is not in c++ format is it? can someone help me translate this to c++....

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int main()
    {
    	FILE  *fp; char v[1000]; int i,j,d;
    	fp=fopen("outfile.txt","w");
    	
    	for(i=1;i<=999;i++)
    	{
    		v[i]='t';
    	}
    
    	for(i=4;i<=999;i++)
    	{ 
    		for(j=2;j<=i/2;j++)
    		{ 
    			if( i%j==0)
    			{
    				v[i]='f';
    			}
    		}
    	}
    
    	for (i=1;i<=999;i++)
    	{ 
    		if(v[i]=='t')
    		{							
    			fprintf(fp," \n %d",i);
    		}
    	}
    
    	fclose(fp);
    
    	return 0;
    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    stdio.h -> iostream.h
    printf -> cout
    FILE -> ifstream/ofstream
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    ok so instead of file..i should put in place ifstream?
    well then wht bout all the other weird symbols...after cout..u know the where printf is

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    wht bout all the other weird symbols...after cout..u know the where printf is
    Those are paramaters passed to the printf() function. printf() is part of C++ too, so it should be in your documentation. It will replace %d with the value of variable i. %s will display a string. There are other format characters... you'll have to look them up.

    Code:
    int i = 1;
    int j = 2;
    printf("%d Hello World %d %d", i, j, 9);  // Display:  1 Hello World 2 9
    Last edited by DougDbug; 05-05-2003 at 07:11 PM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21