tags:

views:

424

answers:

3

Hi there

When I was in college i did some C/C++, but in near future i was working in PHP, and now I wish to put more time in learning C/C++.

In PHP i was using print_r() or var_dump() in order to display datas from structures or arrays. Do I have such a default functionality in C, in order to see what do i have in a struct or array?

+3  A: 

There is no such functionality in C++. You can of course write your own Dump() functions. The reason such a feature cannot be generally provided is that the C++ compilation process removes the object metadata needed to structure the dump output. You can of course display structure contents in a debugger, where such metadata is maintained in the debug information.

BTW, are you asking about C or C++? The two languages are quite different, both in features and approach, although neither has var_dump() or similar.

anon
A: 

No, you have to roll your own using one from the cout or C style printf family of output functions for user defined data structures. Similarly, for arrays, (except C-style strings) you will have to loop over all the elements and print each one.

dirkgently
A: 

No, there isn't. Use a debugger like ddd, for example. Most IDEs have one integrated.

soulmerge