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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. printf to an editbox

printf to an editbox

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 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.
  • F Offline
    F Offline
    Freddie Code
    wrote on last edited by
    #1

    I'm developing a project in VC++6.0 MFC. Is there any way to make an editbox the default output device so that a printf statement prints to it? My goal by doing this is to take advantage of all the formatting that comes along with printf. Thanks.

    T M A F 4 Replies Last reply
    0
    • F Freddie Code

      I'm developing a project in VC++6.0 MFC. Is there any way to make an editbox the default output device so that a printf statement prints to it? My goal by doing this is to take advantage of all the formatting that comes along with printf. Thanks.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      if you want, but non with printf() use SetWindowText() instead (and you'll have a look at the MSDN to see how this function is working.. ;):-D)


      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • F Freddie Code

        I'm developing a project in VC++6.0 MFC. Is there any way to make an editbox the default output device so that a printf statement prints to it? My goal by doing this is to take advantage of all the formatting that comes along with printf. Thanks.

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

        You don't need to redirect printf, use sprintf (or CString::Format if you're using MFC/WTL) to put the formatted output in a string. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Pinky, are you pondering what I'm pondering? I think so Brain, but how will we fit the hamster inside the accordion?

        1 Reply Last reply
        0
        • F Freddie Code

          I'm developing a project in VC++6.0 MFC. Is there any way to make an editbox the default output device so that a printf statement prints to it? My goal by doing this is to take advantage of all the formatting that comes along with printf. Thanks.

          A Offline
          A Offline
          avenger_sb25
          wrote on last edited by
          #4

          The best solution: Use "wsprintf(...)" print a formatted line to a string and display that string in an edit BOX as follows:

          char str[100];
          int i=10;
          float f=12.0045;
          CEdit wEdit;
          wsprintf(str, "This is formatted string with %.2f and %d. lol", f, i);
          //now display this formatted string in the EDIT BOX
          wEdit.SetWindowText(str);

          wsprintf The wsprintf function formats and stores a series of characters and values in a buffer. Any arguments are converted and copied to the output buffer according to the corresponding format specification in the format string. The function appends a terminating null character to the characters it writes, but the return value does not include the terminating null character in its character count. CHECK MSDN www.msdn.com[^] FOR FURTHER DETAILS Hope that works 4 u. Tell me if u love my solution ;) ...Avenger


          Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

          1 Reply Last reply
          0
          • F Freddie Code

            I'm developing a project in VC++6.0 MFC. Is there any way to make an editbox the default output device so that a printf statement prints to it? My goal by doing this is to take advantage of all the formatting that comes along with printf. Thanks.

            F Offline
            F Offline
            Freddie Code
            wrote on last edited by
            #5

            The sprintf idea works great with MFC CString Edit Boxes. :-D I could not get SetWindowText() to work with the CString Edit Box in MFC. Probablly just my lack of VC experience.... Thanks for the suggestions.

            T 1 Reply Last reply
            0
            • F Freddie Code

              The sprintf idea works great with MFC CString Edit Boxes. :-D I could not get SetWindowText() to work with the CString Edit Box in MFC. Probablly just my lack of VC experience.... Thanks for the suggestions.

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              you only had to cast your CString object into a C-style string with (LPCTSTR)MyStringObject;


              TOXCCT >>> GEII power

              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