reading data type

A

Adam Chapman

Hi,

Im completely new to c++ and I am trying to interface some c++ source
code with matlab. Mt question is:

I there a way to find the data type of a variable other than searching
through the code to see where it was defined?

What I would like to do is use a printf statement to show the type of
a certain variable.

Thanks for any help offered.

Adam
 
A

Alf P. Steinbach

* Adam Chapman:
Im completely new to c++ and I am trying to interface some c++ source
code with matlab. Mt question is:

I there a way to find the data type of a variable other than searching
through the code to see where it was defined?

What I would like to do is use a printf statement

Being a novice in C++, it would be much less chance of things going
wrong by using the more type safe iostreams, e.g.

std::cout << "Hello" << std::endl;

It typically drags in a lot of baggage that makes your executable or
library or whatever insanely large, and the code is more verbose too.

But better a bloated thing that works than a lean and mean one that's
incorrect.

to show the type of a certain variable.

std::cout << typeid(v).name() << std::endl;

(IIRC).

However, a C++ implementation is not required to produce any
human-readable text here.

But it might help.

Another more practical way is to use a modern IDE, right click on the
variable and choose "go to definition" or the like, or just hover the
mouse over the variable to see the definition.

Cheers, & hth.,

- Alf
 
J

James Kanze

* Adam Chapman:

[...]
Another more practical way is to use a modern IDE, right click on the
variable and choose "go to definition" or the like, or just hover the
mouse over the variable to see the definition.

You don't need anything very modern. Ctags worked with the
original vi to do just that.

Of course, just knowing the type isn't all that useful. You
need to see the documentation concerning the variable, and the
type, if it is a user defined type. And how to find this
depends very much on what the original programmer has done.

Do IDE's support user documentation? I seem to recall hearing
that they do, but I've never used them enough to know. (Of
course, you'll want to read the documentation before going into
the editor. But a quick short cut to the documentation, for the
details you've forgotten, is definitly a good thing.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,226
Latest member
KristanTal

Latest Threads

Top