0

Maybe I missed something, but I cant figure out why Visual Studio 2008 isn't seeing the rdbuf() procedure. Here is my code:

16. #include "DebugBuffer/BufferedStringBuf.h"
17.
18. BufferedStringBuf debug_buffer(256);
19. std::cout.rdbuf(&debug_buffer);

The BufferedStringBuf class is from this page: http://www.devmaster.net/forums/showthread.php?t=7037

Which produces the following error:

...src\main.cpp(19) : error C2143: syntax error : missing ';' before '.'

All I want to do is redirect std::cout to the Visual Studio Output window using OutputDebugString()..

Mikepote
  • 6,042
  • 3
  • 34
  • 38
  • 3
    Do you `#include ` somewhere? Also `BufferedStringBuf::writeString()` is pure virtual - you have to implement it in a derived class and instantiate that. – Georg Fritzsche Apr 10 '10 at 16:13

2 Answers2

4

You're not allowed to have executable statements at file-level scope. You can declare variables, but you can't call functions as standalone statements. Move your code into a function (such as gf's answer demonstrates), and you should have no problem.

Community
  • 1
  • 1
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
1

Using the example class given on that site i don't have any problem:

#include <iostream>
#include "DebugBuffer/BufferedStringBuf.h"

class DbgBuf : public BufferedStringBuf {
public:
    DbgBuf() : BufferedStringBuf(255) {}
    virtual void writeString(const std::string &str) {}
};

int main()
{
    DbgBuf debug_buffer;
    std::cout.rdbuf(&debug_buffer);
}

Note that you have to create an instance of a class that derives from BufferedStringBuf because BufferedStringBuf::writeString() is pure virtual, thus making it an abstract class - abstract classes can't be instantiated.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236