943,975 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5664
  • C++ RSS
May 10th, 2007
0

problem with system() function...

Expand Post »
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...
  1. _________________________________________
  2.  
  3. #include <stdlib.h>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. const char *directory;
  10.  
  11. int main(){
  12.  
  13. cout << "enter directory name: ";
  14. cin >> directory;
  15. system("ls -l");
  16. system("mkdir"+directory);
  17. system("mkisofs -J -o filename.iso "+directory);
  18.  
  19. return 0;
  20.  
  21. }
  22. ______________________________________________
notice the + directory?? lol...it's obviously wrong...help pls...
Last edited by WaltP; May 10th, 2007 at 1:30 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Similar Threads
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006
May 10th, 2007
2

Re: problem with system() function...

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.

C++ Syntax (Toggle Plain Text)
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main(){
  9.  
  10. string directory;
  11.  
  12. cout << "enter directory name: ";
  13. cin >> directory;
  14. system("ls -l");
  15. system(("mkdir " + directory).c_str());
  16. system(("mkisofs -J -o filename.iso " + directory).c_str());
  17.  
  18. return 0;
  19.  
  20. }
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
May 10th, 2007
0

Re: problem with system() function...

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?.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
May 10th, 2007
0

Re: problem with system() function...

Click to Expand / Collapse  Quote originally posted by Aia ...
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...
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help with a program
Next Thread in C++ Forum Timeline: exam technique?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC