Search code examples
c++coutoutputdebugstring

calling std::cout.rdbuf() produces syntax error


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()..


Solution

  • 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.