hello there, im having trouble with the system() function...as much as possible, i would like my program to be dynamic...i created a program that will make an iso file...it will ask the user to input the directory that he would like to compress...the problem is, how do i append this to the system() function...here is my code...

_________________________________________

#include <stdlib.h>
#include <iostream>

using namespace std;


const char *directory;

int main(){

         cout << "enter directory name: ";
         cin >> directory;
         system("ls -l");
         system("mkdir"+directory);
         system("mkisofs -J -o filename.iso "+directory);

return 0;

}
______________________________________________

notice the + directory?? lol...it's obviously wrong...help pls...

The easiest way is to make a C++ string and use its concatenation operator (which happens to be the plus operator). Use the c_str method to get the C-style string that's similar to the C++ string you've concatenated that the system function needs.

#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;


int main(){

  string directory;

  cout << "enter directory name: ";
  cin >> directory;
  system("ls -l");
  system(("mkdir " + directory).c_str());
  system(("mkisofs -J -o filename.iso " + directory).c_str());

  return 0;

}

If all that you are going to do is to use C++ to
make calls to commands to the CLI , why don't
you just make a script in bash with those commands?.

If all that you are going to do is to use C++ to
make calls to commands to the CLI , why don't
you just make a script in bash with those commands?.

im going to make this as a function to my other c++ program...i was just testing it... :D

This article has been dead for over six months. Start a new discussion instead.