473,480 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

namespace doubt

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?

Aug 6 '06 #1
2 1303

<bh**************@gmail.comskrev i meddelandet
news:11**********************@75g2000cwc.googlegro ups.com...
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
Aug 6 '06 #2
bh**************@gmail.com 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.

--

Frederick Gotham
Aug 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
5045
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
8
1903
by: Marcin Kalicinski | last post by:
Is the code below ill formed (because operator >> is defined in different namespace than class B)? It fails with VS 2005 Beta. I don't know if I should redesign my code or if I should find a...
6
3410
by: Steffen Hampel | last post by:
I got an rather large project which i recently startet to split up into namespaces. At a certain point the compiler (MSVC 6.0 sp5) began to give me C2871 errors ( 'name' : does not exist or is...
1
1223
by: Baskar RajaSekharan | last post by:
Hi, I want to use IMyExtenderInterface Please let me know what namespace i can include in my project. This is mainly for using Activate.CreateObject method in my project.
10
4964
by: Tamir Khason | last post by:
I have a couple of class libraries wich I built about a year ago. I want to add it no other project, but I want to change their namespaces without recompliation ('cos I'm not sure that I have all...
2
18704
by: james.cssa | last post by:
I want to declare namespace prefix in the Envelope element (i.e. xmlns:xsi and xmlns:xsd) so that the document will be serialized to look like the following. However, I don't know the right way to...
3
1896
by: Wayne Shu | last post by:
When I read the chapter of the namespace of the book C++ Primer(3e). It explain the using directive as follow: "A using directive makes the namespace member names visible as if they were declared...
1
1869
by: ax | last post by:
Dear Experts, I really worry about the following problem.. There is one XML File on my PC located at C:\Test. Hence, there are 2 XSD files on the same path I make an absolut reference in the...
6
2239
by: Juha Nieminen | last post by:
Whenever one sees example C++ code basically anywhere, be it in a book, in a tutorial in the internet, in an online forum or whatever, I would estimate that at least in 99% of cases one sees the...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.