istream and MSC_VER


2005-06-25 05:25:10 PM
cppbuilder49
Hi Folks,
I'm using Borland C++ Builder 6, and have written some functions that
take an istream as a parameter.
In order to do some Unit Testing on these classes, I therefore need to
be able to write data to the istream, and then call the functions.
I tried something like this:
------------------
void readSomething(istream& inStream)
{
string str;
int num;
inStream>>str; // should get: 'XXX'
inStream>>num; // should get: 2
}
istringstream testStream ("XXX\n2\n");
readSomething(testStream);
------------------
This worked great, *until* ... I added the macro _MSC_VER=1100, after
which num now gets trashed (I need the macro for some other code I'm
using that was developed under MSVC).
Does anybody know what's going on, or have an idea for a workaround? I
couldn't see any other possibility to get test data into an istream
apart form writing my own stream class. Is this really true?
Thanks for any help,
Robin.