very basic C++ question
-
I have a very primitive question on C++. If I want include a library I use #include say, #include , iostream header file all I/O functions are declared. But Including a Standard C++ header does not introduce any library names into the current namespace. For that we have to use using namespace std; What does this mean? Does it mean in namespace std all the functions in standard library files are defined and that's why we need that?
-
I have a very primitive question on C++. If I want include a library I use #include say, #include , iostream header file all I/O functions are declared. But Including a Standard C++ header does not introduce any library names into the current namespace. For that we have to use using namespace std; What does this mean? Does it mean in namespace std all the functions in standard library files are defined and that's why we need that?
Binayak wrote: using namespace std; What does this mean? Does it mean in namespace std all the functions in standard library files are defined and that's why we need that? Yes. Having the using statement means that you don't have to qualify each individual std name e.g. std::cout << "Hello world" << std::endl
Lets be honest, isn't it amazing how many truly stupid people you meet during the course of the day. Carry around a pad and pencil, you'll have twenty or thirty names by the end of the day - George Carlin Awasu 1.2.1 [^]: A free RSS reader with support for Code Project.
-
I have a very primitive question on C++. If I want include a library I use #include say, #include , iostream header file all I/O functions are declared. But Including a Standard C++ header does not introduce any library names into the current namespace. For that we have to use using namespace std; What does this mean? Does it mean in namespace std all the functions in standard library files are defined and that's why we need that?
hi 'binayak', so, to help you, i would say that the C++ standard includes some classes and functions into the
std
namespace. In fact, be careful to the diference between the folowing directives :// automatically include functions into std::
#include <iostream>
// dosn't include functions into std::
#include <iostream.h>so, if you use
std::
and you don't want to call it each time you want a function defined inside (for examplecout << "Hello world !"
instead ofstd::cout << "Hello world !"
) you'd prefer the command lineusing namespace std;
Clearly, it tells to the compiler that it will have to look inside the
std::
to find the called function. you could also do this if you don't want all the standard namespace to be used implicitly :#include <iostream>
void main (void) {
using std::cout; // I'm not sure about the syntax, but i know that is possible
cout << "Hello world !";
}hope that's more clear now ;) TOXCCT alias Nicolas C.
-
hi 'binayak', so, to help you, i would say that the C++ standard includes some classes and functions into the
std
namespace. In fact, be careful to the diference between the folowing directives :// automatically include functions into std::
#include <iostream>
// dosn't include functions into std::
#include <iostream.h>so, if you use
std::
and you don't want to call it each time you want a function defined inside (for examplecout << "Hello world !"
instead ofstd::cout << "Hello world !"
) you'd prefer the command lineusing namespace std;
Clearly, it tells to the compiler that it will have to look inside the
std::
to find the called function. you could also do this if you don't want all the standard namespace to be used implicitly :#include <iostream>
void main (void) {
using std::cout; // I'm not sure about the syntax, but i know that is possible
cout << "Hello world !";
}hope that's more clear now ;) TOXCCT alias Nicolas C.
so, to help you, i would say that the C++ standard includes some classes and functions into the std namespace. In fact, be careful to the diference between the folowing directives : No. The
iostream.h
library is only the Microsoft fake of STL iostream and now is obsolete. so, if you use std:: and you don't want to call it each time you want a function defined inside (for example printf("Hello world !") instead of std::printf("Hello world !")) you'd prefer the command lineprintf
is a function fromstdio.h
, notiostream
. Robert-Antonio "Love without sex is like a fish without antlers"