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. CFile and Linefeed

CFile and Linefeed

Scheduled Pinned Locked Moved C / C++ / MFC
comtoolsquestion
6 Posts 3 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.
  • C Offline
    C Offline
    ColinDavies
    wrote on last edited by
    #1

    Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?

    CFile cFoo;

    cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
    {
    cFoo.Write(_T("TEST\n"), 5);
    cFoo.Write(_T("TEST2\n"),6);
    cFoo.Write("TEST3\n",6);
    }
    cFoo.Close();

    Thanks Regardz Colin J Davies

    Sonork ID 100.9197:Colin

    More about me :-)

    J M 3 Replies Last reply
    0
    • C ColinDavies

      Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?

      CFile cFoo;

      cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
      {
      cFoo.Write(_T("TEST\n"), 5);
      cFoo.Write(_T("TEST2\n"),6);
      cFoo.Write("TEST3\n",6);
      }
      cFoo.Close();

      Thanks Regardz Colin J Davies

      Sonork ID 100.9197:Colin

      More about me :-)

      J Offline
      J Offline
      Jay Beckert
      wrote on last edited by
      #2

      Maybe you need to add the \r carrage return?

      cFoo.Write(_T("TEST\n\r"), 6);

      Does that work??

      1 Reply Last reply
      0
      • C ColinDavies

        Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?

        CFile cFoo;

        cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
        {
        cFoo.Write(_T("TEST\n"), 5);
        cFoo.Write(_T("TEST2\n"),6);
        cFoo.Write("TEST3\n",6);
        }
        cFoo.Close();

        Thanks Regardz Colin J Davies

        Sonork ID 100.9197:Colin

        More about me :-)

        J Offline
        J Offline
        Jay Beckert
        wrote on last edited by
        #3

        Hey Colin I just noticed when you open the file the option CFile::typeText is not specified. MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.write.asp Also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.cfile.asp "CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only)." You should get your carrage returns then. Also carrage return\linefeed is counted as one character. Hope I helped. :)

        C 1 Reply Last reply
        0
        • C ColinDavies

          Ok I know this is kinda simple, but why doesn't this produce a linefeed (or carrage return) ?

          CFile cFoo;

          cFoo.Open("bar.txt",CFile::modeCreate | CFile::modeWrite );
          {
          cFoo.Write(_T("TEST\n"), 5);
          cFoo.Write(_T("TEST2\n"),6);
          cFoo.Write("TEST3\n",6);
          }
          cFoo.Close();

          Thanks Regardz Colin J Davies

          Sonork ID 100.9197:Colin

          More about me :-)

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Because a "newline" in DOS/Windows is "\r\n" not just "\n". FYI, if you use CStdioFile::WriteString(), it converts "\n" to "\r\n" on the fly. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

          C 1 Reply Last reply
          0
          • M Michael Dunn

            Because a "newline" in DOS/Windows is "\r\n" not just "\n". FYI, if you use CStdioFile::WriteString(), it converts "\n" to "\r\n" on the fly. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

            C Offline
            C Offline
            ColinDavies
            wrote on last edited by
            #5

            Thaks Mike !! Regardz Colin J Davies

            Sonork ID 100.9197:Colin

            More about me :-)

            1 Reply Last reply
            0
            • J Jay Beckert

              Hey Colin I just noticed when you open the file the option CFile::typeText is not specified. MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.write.asp Also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/\_mfc\_cfile.3a3a.cfile.asp "CFile::typeText Sets text mode with special processing for carriage return–linefeed pairs (used in derived classes only)." You should get your carrage returns then. Also carrage return\linefeed is counted as one character. Hope I helped. :)

              C Offline
              C Offline
              ColinDavies
              wrote on last edited by
              #6

              Thanks Jay !! :-) Regardz Colin J Davies

              Sonork ID 100.9197:Colin

              More about me :-)

              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