Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:50:39+00:00 2026-06-17T09:50:39+00:00

#include stdafx.h #include <string> #include <windows.h> using namespace std; int main() { string FilePath

  • 0
#include "stdafx.h"
#include <string>
#include <windows.h>
using namespace std;

int main()
{
    string FilePath = "C:\\Documents and Settings\\whatever";
    CreateDirectory(FilePath, NULL);
return 0;
}

Error: error C2664: ‘CreateDirectory’ : cannot convert parameter 1 from ‘const char *’ to ‘LPCTSTR’

  1. How do I make this conversion?
  2. The next step is to set today’s date as a string or char and concatenate it with the filepath. Will this change how I do step 1?
  3. I am terrible at data types and conversions, is there a good explanation for 5 year olds out there?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:50:41+00:00Added an answer on June 17, 2026 at 9:50 am

    std::string is a class that holds char-based data. To pass a std::string data to API functions, you have to use its c_str() method to get a char* pointer to the string’s actual data.

    CreateDirectory() takes a TCHAR* as input. If UNICODE is defined, TCHAR maps to wchar_t, otherwise it maps to char instead. If you need to stick with std::string but do not want to make your code UNICODE-aware, then use CreateDirectoryA() instead, eg:

    #include "stdafx.h"
    #include <string>
    #include <windows.h>
    
    int main()
    {
        std::string FilePath = "C:\\Documents and Settings\\whatever";
        CreateDirectoryA(FilePath.c_str(), NULL);
        return 0;
    }
    

    To make this code TCHAR-aware, you can do this instead:

    #include "stdafx.h"
    #include <string>
    #include <windows.h>
    
    int main()
    {
        std::basic_string<TCHAR> FilePath = TEXT("C:\\Documents and Settings\\whatever");
        CreateDirectory(FilePath.c_str(), NULL);
        return 0;
    }
    

    However, Ansi-based OS versions are long dead, everything is Unicode nowadays. TCHAR should not be used in new code anymore:

    #include "stdafx.h"
    #include <string>
    #include <windows.h>
    
    int main()
    {
        std::wstring FilePath = L"C:\\Documents and Settings\\whatever";
        CreateDirectoryW(FilePath.c_str(), NULL);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include stdafx.h #include <iostream> #include <string> using namespace std; const char* funA() { return
project1.cpp #include stdafx.h #include Bicycle.cpp using namespace std; int _tmain(int argc, _TCHAR* argv[]) {
//#include StdAfx.h #include <stdio.h> #include <windows.h> #include <winbase.h> #include <iostream> #include <tchar.h> using namespace
I have the following C++ code: #pragma once #include StdAfx.h #include <string> using namespace
Here is my code so far: #include stdafx.h #include <iostream> #include <string> using namespace
My console app looks like that. #include stdafx.h #include <iostream> #include <cmath> using namespace
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
#include stdafx.h #include string.h #include windows.h bool SCS_GetAgentInfo(char name[32],char version[32], char description[256], const char
The following code #include stdafx.h #include <string> #include <set> #include <boost/algorithm/string/trim.hpp> int _tmain(int argc,
#include stdafx.h #include <iostream> #include <string> #include <windows.h> #include <time.h> unsigned long n =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.