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. cout<<

cout<<

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 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.
  • R Offline
    R Offline
    Rejeesh
    wrote on last edited by
    #1

    In the below given program, 'cout' in the destructor doesn't work. But if the iostream is replaced with iostream.h and the statement using namespace std; is commented then, it works fine and displays - "Hello how are you?" Can anyone explain why is it so? #include iostream using namespace std; struct A { A(){cout<<"Hello";} ~A(){cout<<" you?";} }a; void main( void ) { cout<<" how are"; } //"void (*p[10]) (void (*)());"

    M A M 3 Replies Last reply
    0
    • R Rejeesh

      In the below given program, 'cout' in the destructor doesn't work. But if the iostream is replaced with iostream.h and the statement using namespace std; is commented then, it works fine and displays - "Hello how are you?" Can anyone explain why is it so? #include iostream using namespace std; struct A { A(){cout<<"Hello";} ~A(){cout<<" you?";} }a; void main( void ) { cout<<" how are"; } //"void (*p[10]) (void (*)());"

      M Offline
      M Offline
      markkuk
      wrote on last edited by
      #2

      In VC++ <iostream> and <iostream.h> use different implementations of the run-time library routines, so they work differently.

      R 1 Reply Last reply
      0
      • M markkuk

        In VC++ <iostream> and <iostream.h> use different implementations of the run-time library routines, so they work differently.

        R Offline
        R Offline
        Rejeesh
        wrote on last edited by
        #3

        Thnx for ur reply. But I would like to know why is the STL cout is behaving like this? Is it a bug in STL? "void (*p[10]) (void (*)());"

        1 Reply Last reply
        0
        • R Rejeesh

          In the below given program, 'cout' in the destructor doesn't work. But if the iostream is replaced with iostream.h and the statement using namespace std; is commented then, it works fine and displays - "Hello how are you?" Can anyone explain why is it so? #include iostream using namespace std; struct A { A(){cout<<"Hello";} ~A(){cout<<" you?";} }a; void main( void ) { cout<<" how are"; } //"void (*p[10]) (void (*)());"

          A Offline
          A Offline
          Alvaro Mendez
          wrote on last edited by
          #4

          Don't have an answer for you but you may want to just debug the app to see why the last cout doesn't do anything. Have you tried appending an "endl" to the "you"? Alvaro

          1 Reply Last reply
          0
          • R Rejeesh

            In the below given program, 'cout' in the destructor doesn't work. But if the iostream is replaced with iostream.h and the statement using namespace std; is commented then, it works fine and displays - "Hello how are you?" Can anyone explain why is it so? #include iostream using namespace std; struct A { A(){cout<<"Hello";} ~A(){cout<<" you?";} }a; void main( void ) { cout<<" how are"; } //"void (*p[10]) (void (*)());"

            M Offline
            M Offline
            Mike Nordell
            wrote on last edited by
            #5

            You need to flush "cout" before exiting the application. std::endl takes care of this, as in

            cout << "d'tor" << endl;

            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