Hello,
I am trying to convert this C code to C++. The original code is further down this page. From the changes that I have made till now, the code should work but i keep on getting errors. I am using gcc in ubuntu to compile it.
Thanks in advance for your time.


btree_main.cc: In function ‘int main(int, char**)’:
btree_main.cc:28: error: invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
btree_main.cc:29: error: invalid operands of types ‘float’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
btree_main.cc:30: error: invalid operands of types ‘float’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
btree_main.cc:31: error: expected ‘;’ before ‘)’ token
btree_main.cc:60: error: invalid operands of types ‘double’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
btree_main.cc:61: error: invalid operands of types ‘double’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
make: *** [btree_main.o] Error 1

// Project: B*-tree based placement/floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsors: NSC, Taiwan; Arcadia, Inc.; UMC.
// Version 1.0
// Date:    7/19/2000

//---------------------------------------------------------------------------
#include <iostream>             
#include <cstring>
#include "btree.h"
#include "sa.h"
//---------------------------------------------------------------------------
using namespace std;

int main(int argc,char **argv)

{
   char filename[80],outfile[80]="";
   int times=400, local=7;
   float init_temp=0.9, term_temp=0.1;
   float alpha=1;


   if(argc<=1){
     cout<<"Usage: btree <filename> [times=%d] [hill_climb_stage=%d]\n",
           times, local<<endl;
     cout<<"        [avg_ratio=%.1f] [cost_ratio=%f]\n",avg_ratio,alpha<<endl;
     cout<<"        [lamda=%.2f] [term-temp=%.2f]\n",lamda,term_temp<<endl;
     cout<<"        [output]\n")<<endl;
     return 0;
   }else{
     int argi=1;
     if(argi < argc) strcpy(filename, argv[argi++]);
     if(argi < argc) times=atoi(argv[argi++]);
     if(argi < argc) local=atoi(argv[argi++]);
     if(argi < argc) avg_ratio=atof(argv[argi++]);
     if(argi < argc) alpha=atof(argv[argi++]);
     if(argi < argc) lamda=atof(argv[argi++]);
     if(argi < argc) term_temp=atof(argv[argi++]);
     if(argi < argc) strcpy(outfile, argv[argi++]);
   }

   try{
     double time = seconds();
     B_Tree fp(alpha);
     fp.read(filename);
     //fp.show_modules();
     fp.init();
     double last_time =  SA_Floorplan(fp, times, local, term_temp);
     //Random_Floorplan(fp,times);
     fp.list_information();

     { // log performance and quality
       if(strlen(outfile)==0)
         strcpy(outfile,strcat(filename,".res"));

       last_time = last_time - time;
       cout<<"CPU time       = %.2f\n",seconds()-time<<endl;
       cout<<"Last CPU time  = %.2f\n",last_time<<endl;
       FILE *fs= fopen(outfile,"a+");
       

       fprintf(fs,"CPU= %.2f, Cost= %.6f, Area= %.0f, Wire= %.0f, Dead=%.4f ",
               last_time, float(fp.getCost()),  float(fp.getArea()),
                float(fp.getWireLength()), float(fp.getDeadSpace()));
       fprintf(fs," :%d %d %.0f \n", times, local, avg_ratio);
       fclose(fs);
     }

   }catch(...){}
   return 1;
}

This is the original code.

// Project: B*-tree based placement/floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsors: NSC, Taiwan; Arcadia, Inc.; UMC.
// Version 1.0
// Date:    7/19/2000

//---------------------------------------------------------------------------
#include <iostream>             
#include <cstring>
#include "btree.h"
#include "sa.h"
//---------------------------------------------------------------------------
using namespace std;

int main(int argc,char **argv)

{
   char filename[80],outfile[80]="";
   int times=400, local=7;
   float init_temp=0.9, term_temp=0.1;
   float alpha=1;


   if(argc<=1){
     cout<<"Usage: btree <filename> [times=%d] [hill_climb_stage=%d]\n",
           times, local<<endl;
     cout<<"        [avg_ratio=%.1f] [cost_ratio=%f]\n",avg_ratio,alpha<<endl;
     cout<<"        [lamda=%.2f] [term-temp=%.2f]\n",lamda,term_temp<<endl;
     cout<<"        [output]\n")<<endl;
     return 0;
   }else{
     int argi=1;
     if(argi < argc) strcpy(filename, argv[argi++]);
     if(argi < argc) times=atoi(argv[argi++]);
     if(argi < argc) local=atoi(argv[argi++]);
     if(argi < argc) avg_ratio=atof(argv[argi++]);
     if(argi < argc) alpha=atof(argv[argi++]);
     if(argi < argc) lamda=atof(argv[argi++]);
     if(argi < argc) term_temp=atof(argv[argi++]);
     if(argi < argc) strcpy(outfile, argv[argi++]);
   }

   try{
     double time = seconds();
     B_Tree fp(alpha);
     fp.read(filename);
     //fp.show_modules();
     fp.init();
     double last_time =  SA_Floorplan(fp, times, local, term_temp);
     //Random_Floorplan(fp,times);
     fp.list_information();

     { // log performance and quality
       if(strlen(outfile)==0)
         strcpy(outfile,strcat(filename,".res"));

       last_time = last_time - time;
       cout<<"CPU time       = %.2f\n",seconds()-time<<endl;
       cout<<"Last CPU time  = %.2f\n",last_time<<endl;
       FILE *fs= fopen(outfile,"a+");
       

       fprintf(fs,"CPU= %.2f, Cost= %.6f, Area= %.0f, Wire= %.0f, Dead=%.4f ",
               last_time, float(fp.getCost()),  float(fp.getArea()),
                float(fp.getWireLength()), float(fp.getDeadSpace()));
       fprintf(fs," :%d %d %.0f \n", times, local, avg_ratio);
       fclose(fs);
     }

   }catch(...){}
   return 1;
aa}

Your original C code uses cout?

line 26: The value of argc will not be less than 1. The first argument to the program is the name of the program itself (on most operating systems).

line 27 and 28: What are you trying to do there? cout knows nothing about %d format string. You need to study how to use cout before continuing with that program.

Your original C code uses cout?

Hello,
I was a little careless when i posted the code. This is the original code. as you can see it does not use cout.

// Project: B*-tree based placement/floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsors: NSC, Taiwan; Arcadia, Inc.; UMC.
// Version 1.0
// Date:    7/19/2000

//---------------------------------------------------------------------------
//#include <iostream>             
#include <cstring>
#include "btree.h"
#include "sa.h"
//---------------------------------------------------------------------------
using namespace std;

int main(int argc,char **argv)

{
   char filename[80],outfile[80]="";
   int times=400, local=7;
   float init_temp=0.9, term_temp=0.1;
   float alpha=1;


   if(argc<=1){
     printf("Usage: btree <filename> [times=%d] [hill_climb_stage=%d]\n",
           times, local);
     printf("        [avg_ratio=%.1f] [cost_ratio=%f]\n",avg_ratio,alpha);
     printf("        [lamda=%.2f] [term-temp=%.2f]\n",lamda,term_temp);
     printf("        [output]\n");
     return 0;
   }else{
     int argi=1;
     if(argi < argc) strcpy(filename, argv[argi++]);
     if(argi < argc) times=atoi(argv[argi++]);
     if(argi < argc) local=atoi(argv[argi++]);
     if(argi < argc) avg_ratio=atof(argv[argi++]);
     if(argi < argc) alpha=atof(argv[argi++]);
     if(argi < argc) lamda=atof(argv[argi++]);
     if(argi < argc) term_temp=atof(argv[argi++]);
     if(argi < argc) strcpy(outfile, argv[argi++]);
   }

   try{
     double time = seconds();
     B_Tree fp(alpha);
     fp.read(filename);
     //fp.show_modules();
     fp.init();
     double last_time =  SA_Floorplan(fp, times, local, term_temp);
     //Random_Floorplan(fp,times);
     fp.list_information();

     { // log performance and quality
       if(strlen(outfile)==0)
         strcpy(outfile,strcat(filename,".res"));

       last_time = last_time - time;
       printf("CPU time       = %.2f\n",seconds()-time);
       printf("Last CPU time  = %.2f\n",last_time);
       FILE *fs= fopen(outfile,"a+");
       

       fprintf(fs,"CPU= %.2f, Cost= %.6f, Area= %.0f, Wire= %.0f, Dead=%.4f ",
               last_time, float(fp.getCost()),  float(fp.getArea()),
                float(fp.getWireLength()), float(fp.getDeadSpace()));
       fprintf(fs," :%d %d %.0f \n", times, local, avg_ratio);
       fclose(fs);
     }

   }catch(...){}
   return 1;
}

> I am trying to convert this C code to C++.
So rewrite it then.

What you have at the moment is C/C++ road-kill.

If you really want to make a good C++ program out of this, then you would be using std::string in place of all those char arrays, and std::iostream for all the file I/O.

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.