Computing.Net > Forums > Programming > C++ CreateDirectory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ CreateDirectory

Reply to Message Icon

Name: djas
Date: October 18, 2005 at 10:57:46 Pacific
OS: Windows XP Pro SP2
CPU/Ram: P4 2.40 GHZ 256 RAM
Comment:

Hey guys,
I'm having a bit of a problem using the 'CreateDirectory' function.

:CODE:

#include <iostream>
#include <windows.h>
#include <string>
using namespace std;

int main()
{
string str;
cout << "Type The Name Of The Folder You Want To Create.\n";
cout << "Folder:";
cin >> str;
CreateDirectory(str);
cout << "\nFolder Created!\n";
cin.get();
return 0;
}

:CODE:

It doesn't seem to like that i'm using a variable for the folder name. Any thaughts guys?

thanx

djas



Sponsored Link
Ads by Google

Response Number 1
Name: egkenny
Date: October 18, 2005 at 17:39:53 Pacific
Reply:

1. CreateDirectory requires 2 parameters:
BOOL CreateDirectory(LPCTSTR lpszPath, LPSECURITY_ATTRIBUTES lpsa)

2. The first parameter is a pointer to a charater string. The string type is a class. You need to use the c_str() method to extract the C string from the string object.

:CODE:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;

int main()
{
string str;
LPSECURITY_ATTRIBUTES attr;
attr = NULL;
cout << "Type The Name Of The Folder You Want To Create.\n";
cout << "Folder:";
cin >> str;
CreateDirectory(str.c_str(), attr);
cout << "\nFolder Created!\n";
cin.get();
return 0;
}
:CODE:


0

Response Number 2
Name: djas
Date: October 20, 2005 at 05:53:10 Pacific
Reply:

Thanx I think I understand, Ill read up on it.

djas


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ CreateDirectory

C++ HELP - symbol reference errors www.computing.net/answers/programming/c-help-symbol-reference-errors/17051.html

C++ prgramming help www.computing.net/answers/programming/c-prgramming-help/18183.html

C++ compiling error www.computing.net/answers/programming/c-compiling-error/20145.html