There’s nothing fancy going on in this program, but I get garbage output. Here are the header files I’m including, in case that’s relevant.
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <vector>
#include <string>
#include <sstream>
And I’m using Visual Studio 2008 on Windows XP.
Note that if I print the string to stdout, it prints “test” perfectly fine.

Sometimes the debugger will have trouble picking up proper values if you’ve compiled in Release mode. The compiler might swap around operations or move values to registers, etc.