WinDBG – Visualizing STL containers and strings

With the help of STL extension, this extension can’t visualize each and every containers or classes in STL, rather it displays the mostly used string, wstring, vector<[w]string>, list<[w]string>

for more information give !stl -? in WinDBG input or check in the help file.
See the example below and the output in the debugger console.

// SampleSTL.cpp : Defines the entry point for the console application.
// Compiled with Microsoft Visual C++ 9.0 compiler

#include "stdafx.h"
#include 
#include 
#include

#include 

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

	string str1("Quick");
	string str2("Brown" );

	string str3 = str1 + " " + str2;

	vector vec;

	vec.push_back(str1);
	vec.push_back(str2);
	vec.push_back(str3);

	list lst;

	lst.push_back( str1 );
	lst.push_back( str2 );
	lst.push_back( str3 );

	for( vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)
		cout << (*iter).c_str() << endl;

	cout <::iterator iter = lst.begin(); iter != lst.end(); ++iter)
		cout << (*iter).c_str() << endl;

	return 0;
}

WinDGB output

0:000> !stl str1
[da 0x16fb18]
0016fb18  "Quick"

0:000> !stl str2
[da 0x16faf0]
0016faf0  "Brown"

0:000> !stl str3
[da 0x16fac8]
0016fac8  "Quick Brown"

0:000> !stl vec
	Element 0
[da 0x558358]
00558358  "Quick"
	Element 1
[da 0x558378]
00558378  "Brown"
	Element 2
[da 0x558398]
00558398  "Quick Brown"

0:000> !stl lst
The list has 00000003 elements
	Element 0
[da 0x558400]
00558400  "Brown"
	Element 1
[da 0x558468]
00558468  "Quick Brown"
	Element 2
[da 0xffffffffcdcdcdcd]
cdcdcdcd  "????????????????????????????????"
cdcdcded  "????????????????????????????????"
cdcdce0d  "????????????????????????????????"
cdcdce2d  "????????????????????????????????"
cdcdce4d  "????????????????????????????????"
cdcdce6d  "????????????????????????????????"
cdcdce8d  "????????????????????????????????"
cdcdcead  "????????????????????????????????"
cdcdcecd  "????????????????????????????????"
cdcdceed  "????????????????????????????????"
cdcdcf0d  "????????????????????????????????"
cdcdcf2d  "????????????????????????????????"

NaCL + Pepper (Salt ‘N’ Pepper) – Google Chrome Embraces C++

Google announces the integration of Native Client into Chrome. Native Client allows C and C++ code to be seamlessly executed inside the browser with security restrictions similar to JavaScript. Native Client apps use Pepper, a set of interfaces that provide C and C++ bindings to the capabilities of HTML5. As a result, developers can now leverage their native code libraries and expertise to deliver portable, high performance web apps.

See a better scoop here

Yea browsers are powerful than ever! Long live C++

C++: How to clear the input stream?

What do you expect from the following program?

char x = 0;
std::cout << "Enter a character: " << std::endl;
std::cin >> x;
std::cout << "You entered " << x << std::endl;

int y;
std::cout << "Enter a number: " << std::endl;
std::cin >> y;
std::cout << "You entered " << y << std::endl;

If you enter multiple characters for first input (cin >> x), the stream will take the first character and make it not to prompt for the next input as the input buffer contains additional data. How to deal with such a situation?

There’s a high chance to misinterpret cin.clear() which is actually supposed to sets a new value for the error control state. Standard C/C++ input streams are buffered. The keypresses are buffered by operating system, not by the program. If you’re sure that unnecessary data is present in input stream. You can make use of istream::ignore function to extract and discard the remaining data in the input stream. (Alternatively, you can recursively call cin.get() to make sure that all the data in the buffer are consumed). See the snippet below

char x = 0;
std::cout << "Enter a character: " << std::endl;
std::cin >> x;
std::cout << "You entered " << x << std::endl;

// Clear the stream
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
// alternative method
// while( !cin.eof() && cin.get() == '\n' );

int y;
std::cout << "Enter a number: " << std::endl;
std::cin >> y;
std::cout << "You entered " << y << std::endl;

2010-06-29 – 4:46 PM IST – Updated Angelo’s comment