|
-
January 19th, 2011, 11:59 AM
#1
list all files in a directory c++
Hi!
So, I need to list all the files in the current directory, i have tried several methods but i keep getting this error: cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `const char*' for argument `1' to `int system(const char*)'
What is the best method to do this?
In any case, heres what i have so far...
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
system("DIR "+ExePath());
system("PAUSE");
return 0;
}
string ExePath() {
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
Thanks in Advance!
-0M3G4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|