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. std::cout inside of object

std::cout inside of object

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
11 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.
  • _ _Flaviu

    I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?

    int main()
    {
    CTest test;
    test.ListItems();
    }

    CTest::ListItems()
    {
    CString s(_T("abc"));
    std::out << s;
    }

    and the output console show:

    01378168

    . I have tried several things, but something I am missing. Of course, the app recognize CString.

    V Offline
    V Offline
    Victor Nijegorodov
    wrote on last edited by
    #2

    How about

    CString s(_T("abc"));
    std::out << (LPCTSTR)s;

    1 Reply Last reply
    0
    • _ _Flaviu

      I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?

      int main()
      {
      CTest test;
      test.ListItems();
      }

      CTest::ListItems()
      {
      CString s(_T("abc"));
      std::out << s;
      }

      and the output console show:

      01378168

      . I have tried several things, but something I am missing. Of course, the app recognize CString.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #3

      _Flaviu wrote:

      I have a simple console app.

      Is it Unicode? If so, you may have to use wcout instead.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      • _ _Flaviu

        I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?

        int main()
        {
        CTest test;
        test.ListItems();
        }

        CTest::ListItems()
        {
        CString s(_T("abc"));
        std::out << s;
        }

        and the output console show:

        01378168

        . I have tried several things, but something I am missing. Of course, the app recognize CString.

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

        You need to use one of the methods of CString or CSimpleString that returns a pointer to the characters. The cout function does not understand an MFC object reference.

        _ 1 Reply Last reply
        0
        • L Lost User

          You need to use one of the methods of CString or CSimpleString that returns a pointer to the characters. The cout function does not understand an MFC object reference.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #5

          I succeeded with

          CStringA

          . Thank you all of you !

          L 1 Reply Last reply
          0
          • _ _Flaviu

            I succeeded with

            CStringA

            . Thank you all of you !

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

            Hi, The CStringA class has an operator LPCTSTR which means you should be able to use it with cout. There is also a CString::GetBuffer(). Best Wishes, -David Delaune

            V 1 Reply Last reply
            0
            • L Lost User

              Hi, The CStringA class has an operator LPCTSTR which means you should be able to use it with cout. There is also a CString::GetBuffer(). Best Wishes, -David Delaune

              V Offline
              V Offline
              Victor Nijegorodov
              wrote on last edited by
              #7

              Randor wrote:

              The CStringA class has an operator LPCTSTR

              Just a small clarification: CStringA class has an operator LPCSTR. :laugh:

              L 1 Reply Last reply
              0
              • V Victor Nijegorodov

                Randor wrote:

                The CStringA class has an operator LPCTSTR

                Just a small clarification: CStringA class has an operator LPCSTR. :laugh:

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

                Yep, I always disliked the TCHAR hacks. Although I do still find myself using the L and _T macros for string literals. :) Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh: Best Wishes, -David Delaune

                V 1 Reply Last reply
                0
                • L Lost User

                  Yep, I always disliked the TCHAR hacks. Although I do still find myself using the L and _T macros for string literals. :) Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh: Best Wishes, -David Delaune

                  V Offline
                  V Offline
                  Victor Nijegorodov
                  wrote on last edited by
                  #9

                  Randor wrote:

                  Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh:

                  I am afraid you remember it wrong (if it was me in the restaurant after MVP summit!) :laugh: I usually drink alcohol if I do not drive nor work. :-O

                  L 1 Reply Last reply
                  0
                  • V Victor Nijegorodov

                    Randor wrote:

                    Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh:

                    I am afraid you remember it wrong (if it was me in the restaurant after MVP summit!) :laugh: I usually drink alcohol if I do not drive nor work. :-O

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

                    Ok, it would have been at the Submixer[^] which is at the commons area. I went out of my way to make it there in the evenings just to see some of the people from the online forums. Actually now that I think about it, it was probably Marius Bancila. In my mind I've always had both you guys organized as the "Codeguru mvps". Best Wishes, -David Delaune

                    V 1 Reply Last reply
                    0
                    • L Lost User

                      Ok, it would have been at the Submixer[^] which is at the commons area. I went out of my way to make it there in the evenings just to see some of the people from the online forums. Actually now that I think about it, it was probably Marius Bancila. In my mind I've always had both you guys organized as the "Codeguru mvps". Best Wishes, -David Delaune

                      V Offline
                      V Offline
                      Victor Nijegorodov
                      wrote on last edited by
                      #11

                      Maybe it was marius. Sometimes he refused alcohol. This picture is from 2009: [https://forums.codeguru.com/attachment.php?attachmentid=29815&d=1237155757\](https://forums.codeguru.com/attachment.php?attachmentid=29815&d=1237155757)

                      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