system call

hi,
im trying to do some system call in unix OS.
Example if i wan to do system("ls -all"):
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
string x="ls";
string y="all";
string z=x + " -" + y;
system(z);    <<== this part error!
return 0;
}


any idea how to solve this problem?
1. That's not a syscall. A syscall transfers control over to the system (because of the interrupt table given to the CPU)
2. Don't use system: http://cplusplus.com/forum/articles/11153/
3. It's because z is an std::string, not a C-string which is what system() takes as a parameter.
Use .c_str() when this problem crops up again; but it's better just not to use system() at all.
system takes a C string: system(z.c_str());
BTW http://www.cplusplus.com/forum/articles/11153/
trollface.jpg
omg? then i have a question on doing this.
actually, im trying to create a text file using system("cat > abc.txt") so the user can directly key in the text input through this prompt. if dun use this step then what other way i can do it?

appreciate your time for answer...
Topic archived. No new replies allowed.