Thread: Is there a way to make the following code portable?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    Is there a way to make the following code portable?

    ....It is quite portable inside the unix land....but I'm looking for a way to make it more standard.
    The two following functions are 1.constructor for a disk class (for a virtual machine) and a way to execute shell directory commands of the host system.

    Code:
    disk::disk(string name,vm* owner)
    {
        /// Check if name is already in the global list
    
    
        ofstream new_disk("disks/"+name+"_prop");
         
        new_disk<<"Name: "<<name<<endl;
        system(("mkdir disks/"+name).c_str());
        
        pwd="disks/"+name+"/";
        disk_of = owner;
        //(*disk_of).shell(); //Works
    }
    Code:
    void disk::command(std::string com)
    {
        istringstream in(com);
        string test;
        in>>test;
        if(test=="cd")
            {
                in>>test;
                pwd+=test; //pwd is a string containing the present working dir to carry over from calls to system();
                system(("cd "+test).c_str());
            }
        else
        {
            system(("cd "+pwd+" && "+com).c_str());
        }
    }
    Last edited by manasij7479; 07-03-2011 at 01:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-29-2011, 08:27 PM
  2. How do I make an EXE out of a C code?
    By NA84 in forum C Programming
    Replies: 4
    Last Post: 11-07-2010, 12:40 AM
  3. How to Make This code more efficient
    By Soulzityr in forum C Programming
    Replies: 9
    Last Post: 04-12-2010, 01:29 AM
  4. Replies: 6
    Last Post: 01-03-2003, 05:40 PM
  5. Make node code - right?
    By MethodMan in forum C Programming
    Replies: 1
    Last Post: 03-24-2002, 02:31 PM