1

I have this code that work's well under VS6 but gives me errors in VS2010 :

void CGreatString::operator>> (char * lpszDest)
{
strcpy (lpszDest, str());
rdbuf()->freeze(0);
}

I have found this for something similar to my problem, but it still didn't work ...

So from what I have understand, ostrstream is deprecated in VS2010, so I tried this :

void CGreatString::operator>> (char * lpszDest)
{
ostringstream os;
string str = os().str();                     //Error 1 and 2
strcpy (lpszDest, str.c_str());
os.rdbuf()->freeze(0);                       //Error 3
}

But I still get errors :

1- error C2064: term does not evaluate to a function taking 0 arguments

2- error C2228: left of '.str' must have class/struct/union

3- error C2039: 'freeze' : is not a member of 'std::basic_stringbuf<_Elem,_Traits,_Alloc>'

Thanks!

Community
  • 1
  • 1
LolCat
  • 539
  • 1
  • 11
  • 24
  • 2
    It should be `os.str();` since `ostringstream` doesn't have an overloaded `operator()` – Seth Carnegie May 16 '12 at 14:26
  • What is *os()*? :) What are you trying to do with freeze function? Streambuf class doesn't have a freeze method - http://www.cplusplus.com/reference/iostream/streambuf/. – besworland May 16 '12 at 14:29
  • True! I only have the freeze problem now! – LolCat May 16 '12 at 14:30
  • The freeze function is to prevent a memory leak. – LolCat May 16 '12 at 14:31
  • 1
    @LolCat it doesn't help, just remove it. Also note that your string will be empty since you don't put anything into `os` – Seth Carnegie May 16 '12 at 14:33
  • @Seth Ok I'll remove it. From what I see, you are right about the fact that the string will be empty, but I didn't write the vs6 code, so I'll look more into that. – LolCat May 16 '12 at 14:40
  • @JerryCoffin he already did :) – Seth Carnegie May 16 '12 at 15:02
  • @SethCarnegie: Yup -- I should have loaded them when it said there were more comments. – Jerry Coffin May 16 '12 at 15:02
  • If you could write an answer, it would be nice for other users, since I can't answer my own question yet (not enough reputation)... Thanks you all! – LolCat May 16 '12 at 15:08
  • In the original VS6 code I assume `CGreatString` is derived from `strstream`, so it copies its own data to the destination. In your "corrected" code you are copying the empty `ostringstream`'s data to the destination, which does nothing. i.e. you've changed an operation on `*this` to an operation on an empty `ostringstream` so that's clearly not equivalent. Maybe you want to change `CGreaatString` to derive from a stringstream instead. – Jonathan Wakely May 16 '12 at 18:19

2 Answers2

0

From the comments on my questions, I've been able to correct it. Thanks!

void CGreatString::operator>> (char * lpszDest)
{
    ostringstream os;
    string str = os.str();
    strcpy (lpszDest, str.c_str());
}
LolCat
  • 539
  • 1
  • 11
  • 24
0

So mini markdown doesn't work in comments. Great, that's just grate.

void CGreatString::operator>> (char * lpszDest)
{
    // copy lpszDest into my CGreatString
    // The code you write does nothing at all.
}
dex black
  • 637
  • 6
  • 8