I want to perform the DOS command 'DIR' within a C++ program. The results to be available to the C++ program also. How do I???
This is a discussion on DOS Command within the C++ Programming forums, part of the General Programming Boards category; I want to perform the DOS command 'DIR' within a C++ program. The results to be available to the C++ ...
I want to perform the DOS command 'DIR' within a C++ program. The results to be available to the C++ program also. How do I???
I don't really know but i think you are talking about
Code:system("dir");
You need to redirect the output to a file, then read the file. (I dunno how to read a file though, so couldn't help you there)
system("dir > dir.txt");
Now you can open dir.txt.
You might have to clean it up before it compiles but that should work...Code:#include <iostream.h> #include <fstream.h> #include <stdlib.h> void read_file (); int main() { char yesno; cout<<"Display conents of directory [y/n]"<<endl; yesno = getch(); switch(yesno) { case 'n': cout<<"Ok, Exiting..."<<endl; return 0; break; case 'y': cout<<"Loading..."<<endl; system("dir > dir.txt"); read_file(); break; default: cout<<"Not an option..."<<endl; return 0; break; } return 0; } void read_file() { char content[1000]; ifstream load; load.open("dir.txt"); load.read(content, 1000); load.close(); cout<<content<<endl; cout<<"Closeing..."<<endl; system("pause"); }
+++
++
+ Sekti
++
+++