khampton
asked on
istream problem
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);
}
// 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
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
//this doesn't work:
ret=FullUMBox(NULL,S,"TEST
return 0;
}
string cistream_to_string(istream
{
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
}
Please explain, how it doesn't work.
Try the following:
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 wors know
S << "line one again" << endl << "line two again" << endl << 123.456;
ret=FullUMBox(NULL,S,"TEST 2",MB_OK);
return 0;
}
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
//this wors know
S << "line one again" << endl << "line two again" << endl << 123.456;
ret=FullUMBox(NULL,S,"TEST
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks -- I did that with an earlier version but it didn't work because I was passing byref. Now that I'm passing byval, it seems to works fine.