Click here to Skip to main content
15,914,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CursorClip Drawing Region Pin
Branislav21-Sep-04 2:15
Branislav21-Sep-04 2:15 
GeneralRe: CursorClip Drawing Region Pin
jw8121-Sep-04 16:59
jw8121-Sep-04 16:59 
GeneralRe: CursorClip Drawing Region Pin
Branislav22-Sep-04 1:51
Branislav22-Sep-04 1:51 
GeneralStatic control for text width Pin
mike :D20-Sep-04 21:51
mike :D20-Sep-04 21:51 
GeneralA question about hint on the button Pin
Rassul Yunussov20-Sep-04 21:43
Rassul Yunussov20-Sep-04 21:43 
GeneralRe: A question about hint on the button Pin
Sujan Christo20-Sep-04 22:32
Sujan Christo20-Sep-04 22:32 
GeneralRe: A question about hint on the button Pin
Rassul Yunussov22-Sep-04 19:11
Rassul Yunussov22-Sep-04 19:11 
Generalweird stream << "behavior" Pin
froyd20-Sep-04 20:47
froyd20-Sep-04 20:47 
Hello!

I ran into a problem, that can be simplified like this, consider the following code:

----8<--------8<--------8<--------8<--------8<----

#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
ofstream("myFile.txt") << "Hello" << endl;
return 0;
}

---->8-------->8-------->8-------->8-------->8----

I would expect this to put "Hello" in the file, but it prints the string address there.
I can't see why.
If you write:

ofstream("myFile.txt") << "Hello" << " men" << endl;

then " men" will be printed correctly, while "Hello" will be printed as the address.

Please note that this happens ONLY if you are using a temporary as the destination stream and ONLY with the leftmost object and ONLY if it's a string constant.

All the following versions behave as I would expect:

ofstream("myFile.txt") << (char*) "Hello" << endl;
//
ofstream("myFile.txt") << 123 << "Hello" << endl;
//
ofstream("myFile.txt") << 1.5f << endl;
//
ofstream myFile("myFile.txt");
myFile << "Hello" << endl;
//

I tried this with Visual Studio 2003 under WinXP and with the GNU compilare under Linux: same result, so it seems to be an intended behavior, because I tend not to think that I found any STL implementation issue. However, I found nothing in the STL documentation about this issue (hey... I found nothing, but maybe something is there hidden to my eyes Wink | ;) ).

I am pretty much convinced that I forgot something very obvious and I'm being stupid, so if anyone can bring some light, it would be nice.

Thanks everyone. Smile | :)

Note: the original problem was found while creating a class deriving from basic_ostream to handle a custom error console, I also found several code sinppets around using temporary unnamed objects derived from basic_ostream but none of them was ever using a string constant as the leftmost object... -_-



C++U,
FrOYd

GeneralActiveX control in VC.Net Pin
Amol Chavan20-Sep-04 20:30
Amol Chavan20-Sep-04 20:30 
Generallocal window hook Pin
Sung-Won20-Sep-04 20:06
Sung-Won20-Sep-04 20:06 
GeneralDoes this Code look robust Pin
Monty220-Sep-04 19:20
Monty220-Sep-04 19:20 
GeneralRe: Does this Code look robust Pin
User 58385220-Sep-04 20:43
User 58385220-Sep-04 20:43 
GeneralRe: Does this Code look robust Pin
Monty220-Sep-04 21:12
Monty220-Sep-04 21:12 
GeneralRe: Does this Code look robust Pin
User 58385221-Sep-04 11:48
User 58385221-Sep-04 11:48 
GeneralMFC: Mouse Right-Click Event to remove and set the black spots in an image from 255 to 0 Pin
pohcb_sonic20-Sep-04 18:07
pohcb_sonic20-Sep-04 18:07 
GeneralRe: MFC: Mouse Right-Click Event to remove and set the black spots in an image from 255 to 0 Pin
Christian Graus20-Sep-04 18:24
protectorChristian Graus20-Sep-04 18:24 
GeneralCListBox formatting Pin
stevieo8420-Sep-04 18:07
stevieo8420-Sep-04 18:07 
GeneralRe: CListBox formatting Pin
Branislav21-Sep-04 1:07
Branislav21-Sep-04 1:07 
Questioncan accelerator keys be intercepted by ActiveX ? Pin
somesoft20-Sep-04 17:11
somesoft20-Sep-04 17:11 
QuestionPassing variables to function called by a thread?!?!?? Pin
Zero_G20-Sep-04 14:37
Zero_G20-Sep-04 14:37 
AnswerRe: Passing variables to function called by a thread?!?!?? Pin
David Crow20-Sep-04 16:56
David Crow20-Sep-04 16:56 
AnswerRe: Passing variables to function called by a thread?!?!?? Pin
stevieo8420-Sep-04 18:20
stevieo8420-Sep-04 18:20 
AnswerRe: Passing variables to function called by a thread?!?!?? Pin
V.20-Sep-04 23:29
professionalV.20-Sep-04 23:29 
QuestionWhy public destructors? Pin
Anonymous20-Sep-04 11:16
Anonymous20-Sep-04 11:16 
AnswerRe: Why public destructors? Pin
Christian Graus20-Sep-04 11:30
protectorChristian Graus20-Sep-04 11:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.