Question

In: Computer Science

As a challenge question i was asked to make a program that can make a newly...

As a challenge question i was asked to make a program that can make a newly made Directory that has the name input from the user. I am to create a program that can make a txt file in the newly created directory.

I am doing this in windows and this is what i got.

#include <windows.h>
#include <string>
#include <iostream>
#include <string.h>
#include <fstream>

#include <TlHelp32.h>

using namespace std;

int main()
{
string Text = "Test string";
ofstream file;

cout << " Type Text here: ";
getline(cin, Text);
cout << "\n\n";
CreateDirectory (("C:\\Users\\Filepath" + Text).c_str(), NULL);
cout << Text << endl;

return 0;
}

Tried many methods, but was not able to. I am suppose to determined if it can be done or not.

Thank you for your time!

Solutions

Expert Solution

Check with the below code:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>


#include <TlHelp32.h>
using namespace std;

int main() {


   string Text = "Test string";
   ofstream file;

   cout << " Type Text here: ";
   getline(cin, Text);
   cout << "\n\n";
   file.open("RandimName.txt");
   file << Text;
   file.close();
   return 0;
}

Result:

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again


Related Solutions

In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts...
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts a Celsius temperature to Fahrenheit. Modify that program so it uses a loop to display a table of the Celsius temperatures 0–20, and their Fahrenheit equivalents. Display table on screen and it a .txt file. c++
I need to write a program and can't seem to make it run properly. Someone can...
I need to write a program and can't seem to make it run properly. Someone can help with the coding? It's with python Thanks! Here is the program: The rules of Shut the Box are as follows (abbreviated version): + You have two 5-sided die + You have 5 wooden blocks (labeled 1 through 5) + Each turn, you roll the dice and knock down the blocks corresponding to the number on each die + You have to knock down...
How can I make this program able to implement listener for the editable text field: ///////////////////////////////...
How can I make this program able to implement listener for the editable text field: /////////////////////////////// KiloConverter.java ////////////////////////// import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class KiloConverter extends JFrame { // constant for converting km to miles static final double KM_TO_MILES = 0.6214; // important components that needs to be accessed throughout the program private JTextField input, output; // constructor initializing GUI public KiloConverter() { // passing title...
how can i make this program in python? Captain Øks is on his way to conquer...
how can i make this program in python? Captain Øks is on his way to conquer Mosefjell. He has a map of the area and he is in his camp at the designated place on the map. The map is divided into cells. For each cell, the height is given. Captain Øks is not happy, the landscape is full of hills, and he hates to climb both up and down. He has hired you to write a program that will...
Here is my C++ program so far. Is there anyway I can make it display an...
Here is my C++ program so far. Is there anyway I can make it display an error if the user enters a float? Thanks #include <iostream> using namespace std; // Creating a constant for the number of integers in the array const int size = 10; int main() { // Assigning literals to the varibles int a[size]; int sum=0; float avg; // For loop that will reiterate until all 10 integers are entered by the user for(int i=0; i<size; i++)...
I need a short and clear opinion so I can understand the question and make my...
I need a short and clear opinion so I can understand the question and make my own opinion Writing in the 19th century, the British economist Thomas Malthus argued that the law of diminishing marginal returns implied eventual misery for humanity because, in the case of agriculture, there is a fixed amount of available land and additional labor would only yield ever smaller increases in food production. The inevitable result, as Malthus saw it, was that population growth would eventually...
Using java, I need to make a program that reverses a file. The program will read...
Using java, I need to make a program that reverses a file. The program will read the text file character by character, push the characters into a stack, then pop the characters into a new text file (with each character in revers order) EX: Hello World                       eyB       Bye            becomes    dlroW olleH I have the Stack and the Linked List part of this taken care of, I'm just having trouble connecting the stack and the text file together and...
I posted this question before too but answer was wrong can you please make sure the...
I posted this question before too but answer was wrong can you please make sure the answer is right Required information [The following information applies to the questions displayed below.] In 2018, the Westgate Construction Company entered into a contract to construct a road for Santa Clara County for $10,000,000. The road was completed in 2020. Information related to the contract is as follows: 2018 2019 2020 Cost incurred during the year $ 2,204,000 $ 3,192,000 $ 2,424,400 Estimated costs...
Detect 3 or more consecutive 1’s. for this question , how can i make a state...
Detect 3 or more consecutive 1’s. for this question , how can i make a state diagram and state table ? based on what ? also, how can i know the state S0 will go for s2 or S0 for S1 and so on?
I thought for this type of question I am supposed to make a chart with the...
I thought for this type of question I am supposed to make a chart with the inventory, purchases, sales, etc., but instead, these questions are throwing me off for the little understanding I have on this new topic... Kayla Company uses the perpetual inventory system and the LIFO method. The following information is available for the month of June: June 1 Beginning inventory 200 units @ $5 12 Purchase on account 400 units @ $6 15 Sales on account 440...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT