Video není dostupné.
Omlouváme se.

Output File Streams in C++ (Writing to Files)

Sdílet
Vložit
  • čas přidán 12. 08. 2024

Komentáře • 36

  • @epicinator2372
    @epicinator2372 Před 11 měsíci

    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.

  • @jwilli3008
    @jwilli3008 Před 2 lety +1

    Thank you! I learned a lot from this :) I appreciate it

  • @MarcusHCrawford
    @MarcusHCrawford Před 10 měsíci

    Thanks for this.

  • @Autumn9988
    @Autumn9988 Před 5 lety +6

    this video is so helpful! i have my midterm in an hour kfjsojfo

    • @zeerak8294
      @zeerak8294 Před 3 lety +1

      how did the midterm go lmao

    • @Autumn9988
      @Autumn9988 Před 3 lety +4

      @@zeerak8294 LMFAO I aced it 😎 but also it was open note BAHAHA

  • @vavanfarizzaman4600
    @vavanfarizzaman4600 Před 2 lety

    thank you

  • @roberryjannello4856
    @roberryjannello4856 Před 3 lety

    Okay so how to save or write the data if I have 2 or more outputs with the same name of declaration?

  • @BobMarley-qh2qs
    @BobMarley-qh2qs Před rokem

    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 .

  • @Diy.floraxoxo
    @Diy.floraxoxo Před měsícem

    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.

  • @a77mvd
    @a77mvd Před 4 lety +2

    ok what if we want for example to loop and the user enter couple of times but each time in a new line ?

    • @nassmynredzuan99
      @nassmynredzuan99 Před 3 lety +1

      maybe in that particular while or for loop, you can add on,
      *
      **
      cout > n;
      cout interger;
      cout

  • @arshitaanchaliya1583
    @arshitaanchaliya1583 Před 2 lety

    How to get the output of c program from terminal into txt file

  • @aaravsaini8687
    @aaravsaini8687 Před rokem

    Ayo Sebastian Vettel 😳

  • @sparkle7670
    @sparkle7670 Před 2 lety

    It's not working
    Do i have to save the file in vision studio or it just automatically creates file ?

  • @Gee-bg2rv
    @Gee-bg2rv Před 2 lety

    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?

    • @MarcusHCrawford
      @MarcusHCrawford Před 10 měsíci

      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.

  • @lukostello
    @lukostello Před 3 lety

    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"

    • @ProgrammingwithDrHayes
      @ProgrammingwithDrHayes  Před 3 lety +1

      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/"

    • @lukostello
      @lukostello Před 3 lety

      @@ProgrammingwithDrHayes thanks, I'm writing a program that takes text from other places in my computer.

  • @anasdev1553
    @anasdev1553 Před 2 lety +1

    I know that this is old but please, can you tell me a way to change the location that txt file exports in?

    • @ProgrammingwithDrHayes
      @ProgrammingwithDrHayes  Před 2 lety

      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")).

    • @anasdev1553
      @anasdev1553 Před 2 lety

      @@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)

    • @ProgrammingwithDrHayes
      @ProgrammingwithDrHayes  Před 2 lety

      @@anasdev1553 My pleasure! You may be interested in my video on generating psudo-random numbers. czcams.com/video/_VkEnualCV8/video.html
      With a random number, you could pick a random location.

    • @anasdev1553
      @anasdev1553 Před 2 lety

      @@ProgrammingwithDrHayes oh ok
      il check it out
      thanks!

  • @leoodaya3201
    @leoodaya3201 Před 2 lety +2

    fileOut.open(filename);
    it's not working on me.

    • @DalluCS
      @DalluCS Před 5 měsíci

      fileOut.open("filename");

  • @jonathan1q2w3e4r
    @jonathan1q2w3e4r Před 3 lety +3

    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

    • @ProgrammingwithDrHayes
      @ProgrammingwithDrHayes  Před 3 lety +3

      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";

  • @priscusemmanuel8403
    @priscusemmanuel8403 Před rokem

    Can you please help me to do this on Xcode?

  • @zfazzershroudvietcynide64e58

    the fileOut.open(filename); has an error help!!!!!!

    • @ProgrammingwithDrHayes
      @ProgrammingwithDrHayes  Před 3 lety

      What is the error that is displayed? Did you set the correct value to filename?

    • @MarcusHCrawford
      @MarcusHCrawford Před 10 měsíci

      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

    • @zfazzershroudvietcynide64e58
      @zfazzershroudvietcynide64e58 Před 10 měsíci

      @@MarcusHCrawford hahaha got it finally after 2 years

    • @MarcusHCrawford
      @MarcusHCrawford Před 10 měsíci +1

      @@zfazzershroudvietcynide64e58
      Hey, you stuck with it, right? That’s what I like to hear.