hey i've been working on a console project in which i have to take a file as input and then compress it using zlib and give it as output. i want to know how should i start .
i want it to read from a file with certain data, but that file doesn't exist so what do i do?? the problem says i need to make an input file with this data and then write from it.
So I use visual studio and I copy pasted your code exactly how it is here, but it doesn’t create a file? The program runs but doesn’t actually create an output file. I’m not sure if something is wrong with my computer or visual studio?
Did you look in the right place for the file? Make sure you’re using the right flag. If a file is marked for input, it won’t automatically create the file. It will give an error because the file doesn’t exist. But an output file will automatically create itself.
You can open a file stream using an absolute path by using a forward slash instead of a back slash. For example, fileOut.open("A:/Program files/nand2tetris/projects/06/max/Max.hack"); However, it is generally better to use relative paths: fileOut.open("max/Max.hack"); Note that in Windows, you cannot write files to "Program Files" without running your program as Administrator. In that case, it would be best to put your file somewhere else, like "%APPDATA%/max/"
When calling the open() method, you pass a relative path (e.g., fileOut.open("../files/output.txt")) or use an absolute path (e.g., fileOut.open("C:\output.txt")).
@@ProgrammingwithDrHayes oh thankssssss now last question, sorry for bothering ya but I am kinda new and you seem expert whatif I want the location to be random? (I am trying to make a bot that can play hide and seek so it would make sense if the location changes everytime)
@@anasdev1553 My pleasure! You may be interested in my video on generating psudo-random numbers. ruclips.net/video/_VkEnualCV8/видео.html With a random number, you could pick a random location.
Hi, Great video I am working on a project with my son. We are trying to merge a string of text and a variable similar to the way a mail merge works in a word processor. Any help is appreciated. Here is an example below of what I am describing: Dear, (patientName) Your appointment is scheduled for (appointmentDate) Sincerely, Dr. Dre
You can concatenate string values with the + operator. string name = "Bob"; string time = "11 am on 8/30"; string message; message = "Dear " + name + " "; message += "Your appointment is scheduled for " + time + ". "; message += "Sincerely, Dr. Dre";
Make sure to do the #include preprocessor directive, then declare the object before trying to open it. ofstream outfile; outfile.open(“file.ext”); If (!outfile.open){error;} outfile
A genuine individual not begging for a subscription. I appreciate that. You get a like as well as a viewer who is now well informed. Thank you.
Thank you! I learned a lot from this :) I appreciate it
Thanks for this.
thank you
Okay so how to save or write the data if I have 2 or more outputs with the same name of declaration?
this video is so helpful! i have my midterm in an hour kfjsojfo
how did the midterm go lmao
@@zeerak8294 LMFAO I aced it 😎 but also it was open note BAHAHA
hey i've been working on a console project in which i have to take a file as input and then compress it using zlib and give it as output. i want to know how should i start .
How to get the output of c program from terminal into txt file
i want it to read from a file with certain data, but that file doesn't exist so what do i do?? the problem says i need to make an input file with this data and then write from it.
ok what if we want for example to loop and the user enter couple of times but each time in a new line ?
maybe in that particular while or for loop, you can add on,
*
**
cout > n;
cout interger;
cout
It's not working
Do i have to save the file in vision studio or it just automatically creates file ?
So I use visual studio and I copy pasted your code exactly how it is here, but it doesn’t create a file? The program runs but doesn’t actually create an output file. I’m not sure if something is wrong with my computer or visual studio?
Did you look in the right place for the file? Make sure you’re using the right flag. If a file is marked for input, it won’t automatically create the file. It will give an error because the file doesn’t exist. But an output file will automatically create itself.
how do I open files from underneath the scope of the folder my cpp file is in for example :"A:\Program files
and2tetris\projects\06\max\Max.hack"
You can open a file stream using an absolute path by using a forward slash instead of a back slash. For example,
fileOut.open("A:/Program files/nand2tetris/projects/06/max/Max.hack");
However, it is generally better to use relative paths:
fileOut.open("max/Max.hack");
Note that in Windows, you cannot write files to "Program Files" without running your program as Administrator. In that case, it would be best to put your file somewhere else, like "%APPDATA%/max/"
@@ProgrammingwithDrHayes thanks, I'm writing a program that takes text from other places in my computer.
Ayo Sebastian Vettel 😳
I know that this is old but please, can you tell me a way to change the location that txt file exports in?
When calling the open() method, you pass a relative path (e.g., fileOut.open("../files/output.txt")) or use an absolute path (e.g., fileOut.open("C:\output.txt")).
@@ProgrammingwithDrHayes oh thankssssss
now last question, sorry for bothering ya but I am kinda new and you seem expert
whatif I want the location to be random?
(I am trying to make a bot that can play hide and seek so it would make sense if the location changes everytime)
@@anasdev1553 My pleasure! You may be interested in my video on generating psudo-random numbers. ruclips.net/video/_VkEnualCV8/видео.html
With a random number, you could pick a random location.
@@ProgrammingwithDrHayes oh ok
il check it out
thanks!
fileOut.open(filename);
it's not working on me.
fileOut.open("filename");
Can you please help me to do this on Xcode?
The syntax is the same.
Hi, Great video I am working on a project with my son. We are trying to merge a string of text and a variable similar to the way a mail merge works in a word processor. Any help is appreciated. Here is an example below of what I am describing:
Dear, (patientName)
Your appointment is scheduled for (appointmentDate)
Sincerely, Dr. Dre
You can concatenate string values with the + operator.
string name = "Bob";
string time = "11 am on 8/30";
string message;
message = "Dear " + name + "
";
message += "Your appointment is scheduled for " + time + ".
";
message += "Sincerely, Dr. Dre";
the fileOut.open(filename); has an error help!!!!!!
What is the error that is displayed? Did you set the correct value to filename?
Make sure to do the #include preprocessor directive, then declare the object before trying to open it.
ofstream outfile;
outfile.open(“file.ext”);
If (!outfile.open){error;}
outfile
@@MarcusHCrawford hahaha got it finally after 2 years
@@zfazzershroudvietcynide64e58
Hey, you stuck with it, right? That’s what I like to hear.