Creating Directory with Optional Name

hi guys I'm new to programming and I have searched for this topic for quite a while. Yet I ccouldn't fully understand many of them so please forgive me if this question has already been asked for many times.

I am now writing a program that allow users to enter a name of directory and create it. I have been successful on using mkdir ("C:/New Folder")
But I still couldn't make it work as mkdir ("C:/AN_OPTIONAL_NAME")

Btw, I would like to ask if file I/O can open a .pdf file and move/copy it to the new folder created?

Please include all the headers I need. If possible, a example code would be great since I am really new.

thx a lot!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cstdlib>
#include <string>

int main() {
   // Used to send command to system
   std::string command = "mkdir C:\\";
   // Used to store user's foldername
   std::string folderName;

   // Print instructions to user
   std::cout << "Please enter a name for the new folder located at C:\\";
   // Get's user's foldername
   getline(std::cin, folderName, '\n');

   // Puts the strings together
   std::string commandString = command + " " + folderName;

   // Show the file being created
   system("echo on");
   // Making directory
   system(commandString.c_str());
   // Shows files/folders
   system("dir");

   // Exits main
   return 0;
}


Works perfectly fine for me.

I believe your issue might have been with using getline instead of just using std::cin.
Topic archived. No new replies allowed.