2

Possible Duplicate:
Dump facility in C++ like var_dump() in PHP?

I'm not sure does C++ even allow this kind of thing, but I was wondering, could it be possible to write a generic function that could output any type array (std::vector) as plain text, as long as I write myself each of the types output function, for example std::string, float, int, etc.

So, how could I go through the structs types and output them one by one by different output functions made by me?

Community
  • 1
  • 1
Rookie
  • 4,064
  • 6
  • 54
  • 86
  • @ildjarn, does that manage to print_r() any struct? by looking that code it looks like you need to pre-define each struct printing style yourself? – Rookie May 03 '12 at 23:23
  • Any _standard library collection_; user defined types must of course implement their own streaming operators. – ildjarn May 03 '12 at 23:24
  • @Rookie: The pretty-printer prints anything that has a `begin()`/`end()`, and it has sensible defaults for the formatting. You only need to override it if you want something to look different. – Kerrek SB May 03 '12 at 23:26
  • @KerrekSB, so this isnt duplicate question. i wanted to know if i can print any struct without defining own function for each struct itself, but go through the types in it recursively and create output function for only the basic types such as int,float,char array etc. just like you would expect PHP to do it. – Rookie May 04 '12 at 11:11

1 Answers1

0

You should have a look at cxx-prettyprint. http://louisdx.github.com/cxx-prettyprint/

I think it does all your asking for.

André
  • 460
  • 6
  • 18
  • nope it doesnt(?) what i am looking for is a way to output any `struct`, even if that struct is in array: `vector`, so it would go through the struct values and output them according to the functions i would provide for each of the datatypes. So if i have `struct MyStruct {int a; float b; string c;};` it might output such as: `[a = 35567, b = 13.53246, c = "test string"]`. Do you know if this is even possible by c++? – Rookie Oct 11 '12 at 19:18