I can't seem to fix this bug -- it uses and istream. The first call works fine but the 2nd call does not: (Thanks in advance for your assistance!)
// UMBox2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <string>
#include <sstream>
using namespace std;
//prototypes:
string cistream_to_string(istream MyStream);
long FullUMBox(HWND hwnd,istream MsgStm,const string Title,UINT style);
int main()
{
long ret;
stringstream S;
S << "line one" << endl << "line two" << endl << 123.456;
//this displays the correct result:
ret=FullUMBox(NULL,S,"TEST 1",MB_OK);
//this doesn't work:
ret=FullUMBox(NULL,S,"TEST 2",MB_OK);
return 0;
}
string cistream_to_string(istream S)
{
string text;
char ch;
while (true) //infinate loop
{
ch = S.get();
if (S.eof()) break;
text += ch;
}
return text;
}
long FullUMBox(HWND hwnd,istream MsgStm,const string Title,UINT style)
{
string text = cistream_to_string(MsgStm) ;
return MessageBox(hwnd,text.c_str (),Title.c _str(),sty le);
}
khampton
Asked: 2002-05-20