Link to home
Create AccountLog in
Avatar of thready
thready

asked on

boost template read from iostream

Hi Experts,
This template stuff is killing me.  I'm able to successfully read from a stream, one character at a time, but I can't compile when I try to assign the result of my read to 'streamsize'.  The error I get is:

1>..\inc\IOStreamHelper.cpp(117) : error C2440: '=' : cannot convert from 'std::basic_istream<_Elem,_Traits>' to 'std::streamsize'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

How can I fix this function so that it compiles and I can get my return result (so that I know when I've reached EOF)??

Many thanks!
Mike
BOOL CIOStreamHelper::ReadUntil(io::filtering_istream * pIN, char chUntilChar, CString & strText, BOOL bIncludeLastChar)
{
	strText = "";
	char ch;
	std::streamsize result;
	while(TRUE)
	{
		result = pIN->read(&ch, 1);
		if(ch == chUntilChar)
		{
			if(bIncludeLastChar)
				strText += ch;
			return TRUE;
		}
		strText += ch;
	}
	return FALSE;
}

Open in new window

Avatar of thready
thready

ASKER

Basically, the line of code that causes the problem is:
result = pIN->read(&ch, 1);

But if I make this line:
pIN->read(&ch, 1);   // i.e., if I remove the assignment, it compiles and works

However, I need to know when I reach EOF....
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of thready

ASKER

Cool!  What would I do without amazing help like that!?  Many thanks for the quick help!  :-)