473,546 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ 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 1307

<bh************ **@gmail.comskr ev i meddelandet
news:11******** **************@ 75g2000cwc.goog legroups.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
5075
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 the days before PHP got object-oriented features. For instance we currently have:
8
1907
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 better compiler? namespace N1 { class A { }; std::istream &operator >>(std::istream &, A &);
6
3415
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 not a namespace ). I'am using an scheme like this: namespace A { // class declaration
1
1228
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
4968
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 nessesery libraries). Is it possible anyhow change namespace of compiled .NET DLL ? TNX
2
18718
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 do that in Java. <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'...
3
1906
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 outside the namespace at the location where the namespace definition is located." I have some doubt about the using directives for the nested...
1
1876
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 XML file to the 2 XSD files. xmlns:address="C:\Test\file_address.xsd"
6
2244
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 use of "using namespace std;" to get rid of that namespace. In fact, "using namespace ..." is very popular with all documentation and example code of...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1921
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 we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.