cout<<
-
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 (*)());"
-
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 (*)());"
-
In VC++ <iostream> and <iostream.h> use different implementations of the run-time library routines, so they work differently.
-
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 (*)());"
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
-
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 (*)());"
You need to flush "cout" before exiting the application. std::endl takes care of this, as in
cout << "d'tor" << endl;