R
R
RG06092021-10-23 12:42:52
C++ / C#
RG0609, 2021-10-23 12:42:52

How to create a directory whose name consists of a variable?

There is a task: To make "registration". It is conceived so that the user enters his login, and the program creates a folder with his login.

the code
string login;
cout << "Enter login: ";
cin >> login;
CreateDirectory(L"D:\\Test\\" + login.c_str(), NULL);

the vizualka swears, highlights login and writes an error: "the expression must refer to an integer type or an enumeration type without a scope."
What can be done about it? And what does this error actually mean?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cunion, 2021-10-23
@RG0609

You're wrong because you're trying to apply the "+" operator to two C-strings.

#include <iostream>
#include <filesystem>

int main(int argc, char** argv)
{
  std::cout << "Enter your login: " << std::endl;

  std::string login;
  std::getline(std::cin, login);

  std::filesystem::create_directory("D:/Test/" + login);

  return 0;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question