New to namespaces?
Here’s the trick (long answer):
With the ISO C++ standard, the use of namespaces was finally mandated
in a regimented fashion.
If you include the standard C++ headers (e.g. , , …)
rather than the backward compatible “C” headers (e.g. <iostream.h>, …)
it tells the compiler that your application is ISO C++ conforming – and
hence uses namespaces.
In other words, including tells the compiler that you are
using all of the definitions of iostream, but not importing them in
to the global namespace (::), so they must be references in their
namespace (std:: for all ISO C++ definitions).
e.g.
std::iostream myStream;
Using <iostream.h> effectively tells the compiler to import the definitions
into
the global namespace.
That’s the same effect as explicitly importing the std namespace
into your lexical scope with:
using namespace std;
N.B. “Import” here implies that they become part of the global namespace
(:
rather than the compiler assuming all references are to the std
namespace,
which would mean global namespace definitions weren’t visible
without
qualifying them with a ::.
“Colin Burgess” <cburgess@qnx.com> wrote in message
news:c2i9ad$ku6$1@inn.qnx.com…
I think you either need a
using namespace std;
or change it to
std::ofstream
Bill Caroselli wrote:
Bill Caroselli <> qtps@earthlink.net> > wrote:
BC > I need a better understanding of what library I’m linking against
and
BC > what it’s features and limitations are. When I type ‘qcc -V’ I get:
BC > cc: targets available in /etc/qcc:
BC > gcc_ntox86 (GNU C, default)
BC > gcc_ntox86_gpp (GNU C)
BC > gcc_ntox86_cpp (GNU C)
BC > gcc_ntox86_ecpp-ne (GNU C)
BC > gcc_ntox86_ecpp (GNU C)
BC > I thought I was linking against the Dinkum complete libraries. But
this
BC > makes it look like I don’t even have any Dinkum libraries.
BC > QUESTION:
BC > Am I missing an install step?
OK. I’m convinced that I’m using the currect library.
Why am I getting this error below:
#include <fstream
#include <iosfwd
int main ()
{
ofstream o( “test.fil” );
o << “Hello World\n”;
return 0;
}
QCC -Vgcc_ntox86_cpp -Wp,-Wcomment -w9 -Werror -Wno-multichar -Wno-cast-qual
-Wno-shadow -c
make: [/tmp/obj/nto-x86/test/test2.o] Error 1 (ignored)
test2.cc: In function int main()': test2.cc:6:
ofstream’ undeclared (first use this function)
test2.cc:6: (Each undeclared identifier is reported only once
test2.cc:6: for each function it appears in.)
test2.cc:6: parse error before (' test2.cc:7:
o’ undeclared (first use this function)
cc: /usr/lib/gcc-lib/ntox86/2.95.3/cc1plus error 33
–
cburgess@qnx.com