How to return the output string using system("ls *")

Hi,

I am using system("ls *") to list all the files under c++. This function only returns an integer, and I am wondering whether there is a simliar function which can return the output string. Thanks.
What system() does is basically act as though you had typed in that command into the command prompt. It displayed everything just like it would if you had done so. I suppose you could use piping to get the results to a file and read it, but I personally think it would be better just to use your OS's API or another abstraction layer (like boost) to get at the directory information.
Thanks! I am a linux beginner, and could you show me the script for this?
http://www.cplusplus.com/forum/unices/12452/
The example on that link gets a recursive directory listing. You can fix that if you like...

Here is a similar, non-recursive example. It sorts the results, but that can be easily changed, too...
http://www.cplusplus.com/forum/unices/3548/#msg15009

Good luck!
Topic archived. No new replies allowed.