Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. carriage return in CFile::Write

carriage return in CFile::Write

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlackDice
    wrote on last edited by
    #1

    I'm logging errors to a text file, and the text has the 'r\n\' escape characters in there, but it still keeps writing to one continuous line. How do I stop this? If it's broken, I probably did it bdiamond

    F L 2 Replies Last reply
    0
    • B BlackDice

      I'm logging errors to a text file, and the text has the 'r\n\' escape characters in there, but it still keeps writing to one continuous line. How do I stop this? If it's broken, I probably did it bdiamond

      F Offline
      F Offline
      f64
      wrote on last edited by
      #2

      Hi, I just tried this

      CString s = "First line\r\n";
      CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite);
      file.Write(s, s.GetLength());
      s = "second line";
      file.Write(s, s.GetLength());

      and this is what I see in the text.txt file First line second line Do you see something I did differently? Fabian

      B 1 Reply Last reply
      0
      • F f64

        Hi, I just tried this

        CString s = "First line\r\n";
        CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite);
        file.Write(s, s.GetLength());
        s = "second line";
        file.Write(s, s.GetLength());

        and this is what I see in the text.txt file First line second line Do you see something I did differently? Fabian

        B Offline
        B Offline
        BlackDice
        wrote on last edited by
        #3

        yes, you're writing one line at a time, whereas I was writing the whole string at once. But since I wanted to keep the previous contents of the file, I specified CFile::modeNoTruncate as one of the flags, but whatever I write is still appended to the end of the line that was previously there. If it's broken, I probably did it bdiamond

        B F 2 Replies Last reply
        0
        • B BlackDice

          yes, you're writing one line at a time, whereas I was writing the whole string at once. But since I wanted to keep the previous contents of the file, I specified CFile::modeNoTruncate as one of the flags, but whatever I write is still appended to the end of the line that was previously there. If it's broken, I probably did it bdiamond

          B Offline
          B Offline
          Brad Bruce
          wrote on last edited by
          #4

          The seek to end may be truncating the \r\n on the final line. Try adding a \r\n pair to the beginning of your string. Brad

          1 Reply Last reply
          0
          • B BlackDice

            yes, you're writing one line at a time, whereas I was writing the whole string at once. But since I wanted to keep the previous contents of the file, I specified CFile::modeNoTruncate as one of the flags, but whatever I write is still appended to the end of the line that was previously there. If it's broken, I probably did it bdiamond

            F Offline
            F Offline
            f64
            wrote on last edited by
            #5

            Hi, How about this?

            CString s = "\r\none more line";
            CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate);
            file.SeekToEnd();
            file.Write(s, s.GetLength());

            Fabian

            B 1 Reply Last reply
            0
            • F f64

              Hi, How about this?

              CString s = "\r\none more line";
              CFile file("c:\\test.txt", CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate);
              file.SeekToEnd();
              file.Write(s, s.GetLength());

              Fabian

              B Offline
              B Offline
              BlackDice
              wrote on last edited by
              #6

              thank you BradBruce and f64!! that worked!! If it's broken, I probably did it bdiamond

              1 Reply Last reply
              0
              • B BlackDice

                I'm logging errors to a text file, and the text has the 'r\n\' escape characters in there, but it still keeps writing to one continuous line. How do I stop this? If it's broken, I probably did it bdiamond

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                bdiamond wrote: text has the 'r\n\' I hope this is a typo and you actually have '\r\n'.... Elaine :rose: The tigress is here :-D

                B 1 Reply Last reply
                0
                • L Lost User

                  bdiamond wrote: text has the 'r\n\' I hope this is a typo and you actually have '\r\n'.... Elaine :rose: The tigress is here :-D

                  B Offline
                  B Offline
                  BlackDice
                  wrote on last edited by
                  #8

                  YES, that was a typo; I actually did have the right text down, even though I've made stupider mistakes before!!;) If it's broken, I probably did it bdiamond

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups