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. CString Problerm

CString Problerm

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
16 Posts 6 Posters 2 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.
  • D Dy

    A new line in the text? Use \n, there's others too like \t for tab, \\ for '\', etc. Look these up (or 'escape sequences') in MSDN for more info


    Dylan Kenneally London, UK

    Z Offline
    Z Offline
    Zayax
    wrote on last edited by
    #7

    Thanks I've look at MSDN and you were right. but when I want to type like this CString welcome_string = "Hello\ \n World"; so that Hello and World are in different line, there was a "newline is constant" error. :confused: Newbies

    L 1 Reply Last reply
    0
    • Z Zayax

      Thanks I've look at MSDN and you were right. but when I want to type like this CString welcome_string = "Hello\ \n World"; so that Hello and World are in different line, there was a "newline is constant" error. :confused: Newbies

      L Offline
      L Offline
      lucy 0
      wrote on last edited by
      #8

      CString welcome_string = "Hello\ \n**\** World";

      Z 1 Reply Last reply
      0
      • L lucy 0

        CString welcome_string = "Hello\ \n**\** World";

        Z Offline
        Z Offline
        Zayax
        wrote on last edited by
        #9

        lucy wrote: CString welcome_string = "Hello\ \n\ World"; Thanks again. I've tried that but this came out warning C4129: ' ' : unrecognized character escape sequence and the line was still in one line. :confused: Newbies

        L 1 Reply Last reply
        0
        • Z Zayax

          lucy wrote: CString welcome_string = "Hello\ \n\ World"; Thanks again. I've tried that but this came out warning C4129: ' ' : unrecognized character escape sequence and the line was still in one line. :confused: Newbies

          L Offline
          L Offline
          lucy 0
          wrote on last edited by
          #10

          oops, sorry, should be CString welcome_string = "Hello\n\ World";

          Z 1 Reply Last reply
          0
          • L lucy 0

            oops, sorry, should be CString welcome_string = "Hello\n\ World";

            Z Offline
            Z Offline
            Zayax
            wrote on last edited by
            #11

            A lot of thanks for your reply:) BUT the output was Hello|World and not Hello World this was my code void CMyView::OnDraw(CDC* pDC) { CString welcome_string = "Hello\n\ World"; pDC->TextOut(0,0,welcome_string); } Newbies

            L PJ ArendsP 2 Replies Last reply
            0
            • Z Zayax

              A lot of thanks for your reply:) BUT the output was Hello|World and not Hello World this was my code void CMyView::OnDraw(CDC* pDC) { CString welcome_string = "Hello\n\ World"; pDC->TextOut(0,0,welcome_string); } Newbies

              L Offline
              L Offline
              lucy 0
              wrote on last edited by
              #12

              I'm afraid TextOut couldn't handle the "\n", but MessageBox() can. Try MessageBox(welcome_string); and see.

              Z 1 Reply Last reply
              0
              • Z Zayax

                Thanks:rose: Is this means only messagebox can handle "\n"? How about editbox or listbox ia a dialog? Newbies

                L Offline
                L Offline
                lucy 0
                wrote on last edited by
                #13

                ;) I'm not sure. You'd better check that out.

                Z 1 Reply Last reply
                0
                • L lucy 0

                  I'm afraid TextOut couldn't handle the "\n", but MessageBox() can. Try MessageBox(welcome_string); and see.

                  Z Offline
                  Z Offline
                  Zayax
                  wrote on last edited by
                  #14

                  Thanks:rose: Is this means only messagebox can handle "\n"? How about editbox or listbox ia a dialog? Newbies

                  L 1 Reply Last reply
                  0
                  • L lucy 0

                    ;) I'm not sure. You'd better check that out.

                    Z Offline
                    Z Offline
                    Zayax
                    wrote on last edited by
                    #15

                    :)Thanks Newbies

                    1 Reply Last reply
                    0
                    • Z Zayax

                      A lot of thanks for your reply:) BUT the output was Hello|World and not Hello World this was my code void CMyView::OnDraw(CDC* pDC) { CString welcome_string = "Hello\n\ World"; pDC->TextOut(0,0,welcome_string); } Newbies

                      PJ ArendsP Offline
                      PJ ArendsP Offline
                      PJ Arends
                      wrote on last edited by
                      #16

                      As Lucy said, TextOut() can not handle newlines, but DrawText() can. If you want to output multi line text use DrawText(). HTH


                      CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

                      Within you lies the power for good; Use it!

                      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