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

Поделиться
HTML-код
  • Опубликовано: 31 июл 2024

Комментарии • 36

  • @epicinator2372
    @epicinator2372 10 месяцев назад

    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 2 года назад +1

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

  • @MarcusHCrawford
    @MarcusHCrawford 9 месяцев назад

    Thanks for this.

  • @vavanfarizzaman4600
    @vavanfarizzaman4600 2 года назад

    thank you

  • @roberryjannello4856
    @roberryjannello4856 3 года назад

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

  • @Autumn9988
    @Autumn9988 5 лет назад +6

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

    • @zeerak8294
      @zeerak8294 3 года назад +1

      how did the midterm go lmao

    • @Autumn9988
      @Autumn9988 3 года назад +4

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

  • @BobMarley-qh2qs
    @BobMarley-qh2qs Год назад

    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 .

  • @arshitaanchaliya1583
    @arshitaanchaliya1583 2 года назад

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

  • @Diy.floraxoxo
    @Diy.floraxoxo 28 дней назад

    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 4 года назад +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 3 года назад +1

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

  • @sparkle7670
    @sparkle7670 2 года назад

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

  • @Gee-bg2rv
    @Gee-bg2rv 2 года назад

    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 9 месяцев назад

      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 3 года назад

    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  3 года назад +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 3 года назад

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

  • @aaravsaini8687
    @aaravsaini8687 Год назад

    Ayo Sebastian Vettel 😳

  • @anasdev1553
    @anasdev1553 2 года назад +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  2 года назад

      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 2 года назад

      @@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  2 года назад

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

    • @anasdev1553
      @anasdev1553 2 года назад

      @@ProgrammingwithDrHayes oh ok
      il check it out
      thanks!

  • @leoodaya3201
    @leoodaya3201 2 года назад +2

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

    • @DalluCS
      @DalluCS 5 месяцев назад

      fileOut.open("filename");

  • @priscusemmanuel8403
    @priscusemmanuel8403 Год назад

    Can you please help me to do this on Xcode?

  • @jonathan1q2w3e4r
    @jonathan1q2w3e4r 3 года назад +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  2 года назад +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";

  • @zfazzershroudvietcynide64e58
    @zfazzershroudvietcynide64e58 3 года назад

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

    • @ProgrammingwithDrHayes
      @ProgrammingwithDrHayes  3 года назад

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

    • @MarcusHCrawford
      @MarcusHCrawford 9 месяцев назад

      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 9 месяцев назад

      @@MarcusHCrawford hahaha got it finally after 2 years

    • @MarcusHCrawford
      @MarcusHCrawford 9 месяцев назад +1

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