Porting c++ from windows to Linux

This is a discussion on Porting c++ from windows to Linux within the Linux Programming forums, part of the Platform Specific Boards category; I have some old code that figures out Qfactors for me, now I need help on porting it over to ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Location
    KC, MO US
    Posts
    2

    Porting c++ from windows to Linux

    I have some old code that figures out Qfactors for me, now I need help on porting it over to Linus to do some speed test on the Linus computers.

    I been deep in FoxPro 5 for the last year ( the pain!) and now starting this little project.

    Here is the code if you would please point out the place that need to change.

    Code:
          #include <stdio.h>
          #include <time.h>
    	// basic file operations
    	  	#include <iostream>
    		#include <fstream>
    //		using namespace std;
    
    		int	y;
          double  z;
    
    
    void print(const int *v, const int size, ostream &outfile)
    {
      y=y+1;
      if (y == 1000000) {
        	printf ("%15.0f\n",z);
          y=0;
      }
      if (v != 0) {
        for (int i = 0; i < size; i++) {
        outfile << v[i];
        outfile << ",";
        }
        outfile.setf(ios::fixed,ios::floatfield);
        outfile << z;
    	 outfile << "\n";
        z=z+1;
      }
    
    } // print
    
    
    void visit(int *Value, int N, int k, ostream &ofile)
    {
      static level = -1;
      level = level+1;
      Value[k] = level;  
    
      if (level == N)
        print(Value, N, ofile);
      else
        for (int i = 0; i < N; i++)
          if (Value[i] == 0)
            visit(Value, N, i, ofile);
    
      level = level-1; Value[k] = 0;
    }
    
    main()
    {
      const int N = 16 ;
      int Value[N];
      time_t t;
      time_t t1;
      z = 1;
      t = time(0);
      double dif;
    
      ofstream myfile;
      myfile.open ("16Count.txt",ios::app);
      myfile.setf(0,ios::floatfield);            // floatfield not set
      myfile.precision(0);
    
    
      printf("Start  time is %s", ctime(&t));
      myfile << "Start  time is ";
      myfile << ctime(&t);
      myfile << "\n";
    
      for (int i = 0; i < N; i++) {
        Value[i] = 0;
      }
      visit(Value, N, 0, myfile);
    
         t1 = time(0);
         printf("End P1 time is %s", ctime(&t1));
         myfile << "End P1 time is %s";
         dif = difftime(t1,t);
         printf("End time is %.2lf.\n ", dif);
         myfile << dif;
         myfile << "/n";
    
         myfile.close();
    
         printf("Push any key to exit.\n ");
    
    
      return 0;
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,711
    Does this code compile without errors/warnings?

    If no post the complete error messages exactly as they appear in your development environment .

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2011
    Location
    KC, MO US
    Posts
    2
    First run - I get the following..

    Code:
    desktop:~/Desktop$ g++ test.C -o test
    test.C:12: error: \u2018ostream\u2019 has not been declared
    test.C: In function \u2018void print(const int*, int, int&)\u2019:
    test.C:22: error: invalid operands of types \u2018int\u2019 and \u2018const char [2]\u2019 to binary \u2018operator<<\u2019
    test.C:24: error: request for member \u2018setf\u2019 in \u2018outfile\u2019, which is of non-class type \u2018int\u2019
    test.C:24: error: \u2018ios\u2019 has not been declared
    test.C:24: error: \u2018ios\u2019 has not been declared
    test.C:25: error: invalid operands of types \u2018int\u2019 and \u2018double\u2019 to binary \u2018operator<<\u2019
    test.C:26: error: invalid operands of types \u2018int\u2019 and \u2018const char [2]\u2019 to binary \u2018operator<<\u2019
    test.C: At global scope:
    test.C:33: error: \u2018ostream\u2019 has not been declared
    test.C: In function \u2018void visit(int*, int, int, int&)\u2019:
    test.C:35: error: ISO C++ forbids declaration of \u2018level\u2019 with no type
    test.C: In function \u2018int main()\u2019:
    test.C:59: error: \u2018ofstream\u2019 was not declared in this scope
    test.C:59: error: expected \u2018;\u2019 before \u2018myfile\u2019
    test.C:60: error: \u2018myfile\u2019 was not declared in this scope
    test.C:60: error: \u2018ios\u2019 has not been declared
    test.C:61: error: \u2018ios\u2019 has not been declared
    -Dave

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,711
    And have you looked at any of these errors? The major problem with this program is the mixing of C and C++ style input/output functions. The problems with this code are not "porting" issues, the code should not compile with any modern compiler. First I suggest that you decide if you want a C++ or C program. If you choose C++ then go through your code and change/remove the printf(), scanf() calls to C++ style stream handling functions. If you decide to use C then you have much more work to do removing all of the C++ constructs. So I would suggest you stick with C++.

    For a C++ program the fist thing I would do is uncomment the line "using namespace std;".

    Jim

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by jimblumberg View Post
    And have you looked at any of these errors? The major problem with this program is the mixing of C and C++ style input/output functions. The problems with this code are not "porting" issues, the code should not compile with any modern compiler.
    What are you talking about, the code looks pretty much fine. The errors are because 'using namespace std' is commented out.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Looks like you could clean up your terminal by setting it to display Unicode. All those \u2019 codes have got to be a distraction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Porting an input function from linux to windows
    By claphahat in forum C Programming
    Replies: 2
    Last Post: 07-27-2010, 04:55 AM
  2. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 06:57 AM
  3. Porting to Linux?
    By cpjust in forum C Programming
    Replies: 3
    Last Post: 10-18-2007, 05:46 PM
  4. Porting a shared library from Linux to Windows
    By DARKGuy in forum C++ Programming
    Replies: 1
    Last Post: 06-23-2007, 01:45 PM
  5. Replies: 1
    Last Post: 10-18-2005, 10:20 AM

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