namespace doubt

  • Thread starter bharath.donnipad
  • Start date
B

bharath.donnipad

Hi,

I just started learning c++ since 2 months...I have a following doubt.
can someone pls explain.

//include headers
int main()
{
int xyz;
using namespace std;
// some statements

cin>>xyz;
f();
// some statements

} //end of main

f()
{
// some statements
}

How long will be the scope of my statement using namespace std; ? will
the scope of this go after "//end of main" ?
Can i use it in f() also?
 
B

Bo Persson

Hi,

I just started learning c++ since 2 months...I have a following
doubt.
can someone pls explain.

//include headers
int main()
{
int xyz;
using namespace std;
// some statements

cin>>xyz;
f();
// some statements

} //end of main

f()
{
// some statements
}

How long will be the scope of my statement using namespace std; ?
will
the scope of this go after "//end of main" ?

No, it is local.
Can i use it in f() also?

You can add it there too, if you want to. Or you can just use
std::cin, and save some typing. :)


Bo Persson
 
F

Frederick Gotham

(e-mail address removed) posted:
How long will be the scope of my statement using namespace std; ? will
the scope of this go after "//end of main" ?
Can i use it in f() also?


If you want to become a good C++ programmer, then start doing these tests
by yourself -- you'll learn more. It's quite simple -- just try to compile
the following:

#include <string>

void Func();

int main()
{
using namespace std;

Func();
}

void Func()
{
string str;
}

Then, if you're still in doubt, or wish to have your findings confirmed,
post here.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top