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 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...
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++)...
Explain the difference between the CPU and I/O cycles that make up a program. Can a...
Explain the difference between the CPU and I/O cycles that make up a program. Can a process run during an I/O cycle? Explain how the Process Control Block (PCB) is used to manage a process within the system.
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
Hello, How can I make the program print out "Invalid data!!" if the file has a...
Hello, How can I make the program print out "Invalid data!!" if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student grade. Smith Kelly 438975 98.6 A Johnson Gus 210498 72.4 C Reges...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT