namespaces - Create my own pre-name like "std" in C++ -


this question has answer here:

generally when creates console program writes

#include <iostream> #include <stdlib.h>  int main(){     std::cout<<"hello world"<<std::endl;     system("pause"); } 

the std must included call cout , endl statements.

when create library using headers , code in .h , .cpp, , include library, must use name of functions/clases/structs/etc directly. how can make have use pre-word std cout , endl?

it's called namespace.

you can declare own stuff inside namespace this:

namespace mystuff {     int foo(); } 

to define:

int mystuff::foo() {     return 42; } 

to use:

int bar = mystuff::foo(); 

or, import namespace, can std if don't want fully-qualify everything:

using namespace mystuff; // ... int bar = foo(); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -