cout

S

Sharad

> why when I use cout, I must put - using std::cout;

#include <iostream>
using std::cout;

Read about namespaces in your favorite C++ book. std is a namespace.
if i look at iostream, it seem cout is defined in iostream -
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2 ostream cout;

I also see
_STD_BEGIN
_STD_END

are those label in C++?

Compiler specific.
 
W

worlman385

why when I use cout, I must put - using std::cout;

#include <iostream>
using std::cout;

if i look at iostream, it seem cout is defined in iostream -
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2 ostream cout;

I also see
_STD_BEGIN
_STD_END

are those label in C++?
 
D

dertopper

 I had seen quite some library I can use without calling namesapce
like

using XXXXX

for example, like using the Neon HTTP library -

after include the header files, then I can just call function in my
code like

#include <ne_session.h>
ne_set_request_body_buffer(req, REQUEST_BODY, strlen(REQUEST_BODY));

is that means the library Neon does not declare any namespace in
it????

Chances are that Neon is a C library (note that C does have a concept
of namespaces). Note that the function name starts with the prefix
ne_, which can be considered to be some kind of "C namespace".
So there are some library declared to use some namespace and some
other library doesn't??

Exactly. In general, though, it is a good idea to put your C++ library
into a namespace. Else a user of your library may end up with name
conflicts with other libraries.

Regards,
Stuart
 
W

worlman385

I had seen quite some library I can use without calling namesapce
like

using XXXXX

for example, like using the Neon HTTP library -
#include <ne_session.h>
#include <ne_uri.h>
#include <ne_basic.h>
#include <ne_utils.h>
#include <ne_auth.h>

after include the header files, then I can just call function in my
code like

ne_set_request_body_buffer(req, REQUEST_BODY, strlen(REQUEST_BODY));

is that means the library Neon does not declare any namespace in
it????

So there are some library declared to use some namespace and some
other library doesn't??
 
J

James Kanze

why when I use cout, I must put - using std::cout;

There is no "cout" in standard C++, only an "std::cout". You
write std::cout because that is the name of standard out.

You can use a using declaration, as you describe, but I would
recommend only doing so when you have learnt and understood how
namespaces work.
#include <iostream>
using std::cout;
if i look at iostream, it seem cout is defined in iostream -

If <iostream> happens to resolve to a file you can look at
(usually the case), actually looking at that file doesn't
necessarily tell you anything, really.
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2 ostream cout;

See what I mean. There's a lot of non-C++ there, used to invoke
who knows what compiler magic.
I also see
_STD_BEGIN
_STD_END

More compiler (or library) magic. Anything that begins with a
two _, or a _ followed by a capital letter, is implementation
magic (although I can make a good guess about this one).
are those label in C++?

See above. Any symbol beginning with two __ or a _ followed by
a capital letter is implementation magic. (There are actually a
few exceptions: implementation magic, but what exactly is
defined by the standard. __LINE__, __FILE__, __DATE__,
__TIME__, __STDC__ and __cplusplus is the exhaustive list at
present, I think, but the next version of the standard will add
a few more.)
 
W

worlman385

So if a library deson't declare namespace but It has something -
member called like -

table

it's likely may be some you use some other library and import the
header file also include a member called like -

table

there compiler will complain it right?? as there are 2 table member in
2 different header file??

how to solve when this happen?
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top