0

When I'm programming in python it's very convenient to just print whatever datastructure you want to inspect on the screen. Does there exist something like this in C++ for STL datastructures?

It should recurse on the contents of the datastructure and print it with some specific layout for sets, maps, pairs, ..

Griwes
  • 8,163
  • 2
  • 39
  • 69
Jasper
  • 439
  • 5
  • 18
  • Some debuggers have knowledge of the standard library classes, but you can't really inspect data structures of C++ classes unless you have an intimate knowledge of the compiler and class library. C++ doesn't have the introspection facilities dynamic language like Python have. – Some programmer dude Apr 08 '12 at 14:10
  • 1
    possible duplicate of [Pretty-print C++ STL containers](http://stackoverflow.com/questions/4850473/pretty-print-c-stl-containers) – Mike DeSimone Apr 08 '12 at 14:16
  • 1
    Bear in mind that Python requires you to write a `__str__()` or `__repr__()` function for your class in order for it to print out as something other than ``. C++ requires you to overload `ostream& operator< – Mike DeSimone Apr 08 '12 at 14:18

1 Answers1

1

See here and here for pretty printing standard library containers.

Community
  • 1
  • 1
juanchopanza
  • 210,243
  • 27
  • 363
  • 452