[1] using namespace std
In my C++ program, even after applying [1], I need to use the std
namespace with the scope resolution operator, like, std::cout,
std::vector. This I found a little bit cumbersome to always include
std.
I somewhere found a trick to overcome this problem. By using
using std::cout;
using std::vector;
rather than using [1].
is it always done like this or is there any other concept that I still
do not know.
regards,
vijay. 15 3675
You can just add the statement:
using std;
Then you can use cout, vector etc. directly.
Deepa
--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Enter model in plain text;generate sequence diagram in PDF/Word
drdoubt wrote: [1] using namespace std
using namespace std;
In my C++ program, even after applying [1], I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit cumbersome to always include std.
I somewhere found a trick to overcome this problem. By using
using std::cout; using std::vector;
rather than using [1].
is it always done like this or is there any other concept that I still do not know.
If you place using namespace std; in the beginning of a scope, there is
no use for explicit scope resolution in that scope.
For example the following should compile successfully with your compiler:
#include <iostream>
int main()
{
using namespace std;
cout<<"Hello world!\n";
}
--
Ioannis Vranos http://www23.brinkster.com/noicys
EventHelix.com wrote: You can just add the statement:
using std;
Then you can use cout, vector etc. directly.
using namespace std;
--
Ioannis Vranos http://www23.brinkster.com/noicys
"EventHelix.com " <ev********@gma il.com> ????
news:11******** **************@ c13g2000cwb.goo glegroups.com.. . You can just add the statement:
using std;
A little mistake, should be
using namespace std; Then you can use cout, vector etc. directly.
Deepa -- EventStudio 2.5 - http://www.EventHelix.com/EventStudio Enter model in plain text;generate sequence diagram in PDF/Word
[1] using namespace std
But here we need to [1] in every other function where cout, vector may
be used. The problem is that it then becomes a little bit redundant
because we either have to use scope resolution or place [1] in every
function definition.
I just wanted to know whether I can just place [1] in the beginning of
the file and not use scope resolution anywhere else in the program.
regards,
vijay.
vijay wrote: [1] using namespace std
But here we need to [1] in every other function where cout, vector may be used. The problem is that it then becomes a little bit redundant because we either have to use scope resolution or place [1] in every function definition.
I just wanted to know whether I can just place [1] in the beginning of the file and not use scope resolution anywhere else in the program.
You mean to place it in the global scope and thus bring everything
defined in namespace std in the global namespace.
Well, namespace mechanism exists so as to be able to use different
facilities from various libraries.
Suppose you have another library or platform providing some other string
type with the name "string".
If you have not such concerns, then I guess you may place the facilities
you want in the global namespace, however you must keep in mind what the
namespace mechanism exists to offer and what problems may arise in the
future.
--
Ioannis Vranos http://www23.brinkster.com/noicys
Ioannis Vranos wrote: If you have not such concerns, then I guess you may place the facilities you want in the global namespace, however you must keep in mind what the namespace mechanism exists to offer and what problems may arise in the future.
The preferred method however is to use the using namespace std; and
using std::some_facil ity; in as a small scope as possible, for example:
#include <iostream>
#include <ostream>
#include <vector>
void printfunc(const std::vector<int > &someVec)
{
using namespace std;
for(vector<int> ::size_type i=0; i<someVec.size( ); ++i)
cout<<someVec[i]<<endl;
}
int main()
{
using std::vector;
vector<int> vec(10,2);
printfunc(vec);
}
--
Ioannis Vranos http://www23.brinkster.com/noicys
On 22 Feb 2005 10:10:31 -0800, vijay
<Ta***********@ yahoo.com> wrote: [1] using namespace std
But here we need to [1] in every other function where cout, vector may be used. The problem is that it then becomes a little bit redundant because we either have to use scope resolution or place [1] in every function definition.
I just wanted to know whether I can just place [1] in the beginning of the file and not use scope resolution anywhere else in the program.
You certainly can, it's just the same as declaring something extern.
That's what I do, I see no point in hiding the std namespace (doing so
makes the code unreadable with std:: in front of everything). You can
do the same with other namespaces if you want as well.
Chris C
On Tue, 22 Feb 2005 20:19:43 +0200, Ioannis Vranos
<iv*@remove.thi s.grad.com> wrote: Suppose you have another library or platform providing some other string type with the name "string".
Then you have a problem if you want to use std::string as well. I would
do using na,espace std; globally and get the individual things I needed
from the library separately, probably doing
typedef otherlib::strin g OtherStringT;
to get at the one in the other library.
If you have not such concerns, then I guess you may place the facilities you want in the global namespace, however you must keep in mind what the namespace mechanism exists to offer and what problems may arise in the future.
It's normally safe to include namespace std in a module, as long as you
don't also globally include another namespace as well.
Chris C This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: asj |
last post by:
luke: BORRRRRRRRING......the most interesting initiatives are
happening on the client side - in small wireless devices such as
cellphones and smartphones, where J2ME has become the de facto
standard for application development.
Article from Javaworld.com:
"Java everywhere is for world domination"
http://www.javaworld.com/javaworld/jw-08-2003/jw-0822-wireless.html?
Some quotes:
|
by: Mariusz Sakowski |
last post by:
Can someone translate this code to a C++?
repeat
file.Read(bufor, 1);
for p := 1 to KeyCount do
begin
buf := buf xor Keys;
end;
targetFile.Write(bufor, 1);
until file.Size = file.Position;
|
by: JustSomeGuy |
last post by:
I need to write an new class derived from the list class.
This class stores data in the list to the disk if an object
that is added to the list is over 1K in size.
What methods of the std stl list class must Ioverride in order for this
to work?
|
by: Ramon F Herrera |
last post by:
Greetings++, folks:
I am really desperate on this search. I have been looking
all over for a sample code that uses the GPGme (GPG Made Easy)
SDK library to decrypt a file.
I finally found the code (see below), but it doesn't compile
with gcc. Could you folks translate it to C, please?
I specially need the callback function that handles the
passphrase.
|
by: berkay |
last post by:
i have a txt file;
berkay#white
jack#black
smith#jane
writes in it.
and after i run the program it only prints smith jane and crashes
what is wrong?
| |
by: Learnicus |
last post by:
No matter where i choose to create a new application VS2005 tells me that a
webiste already exists there.
Any ideas?
Lenny
|
by: robinsand |
last post by:
I am a new C++ programmer. I am still having trouble with certain data
types and constructors, among other things. I'm not sure if I've
used "std::string" properly throughout this program. I need to fix
that, as well as add exception-handling, make sure everything is
documented properly, and make certain that the code compiles and runs
correctly. I'm under a very tight deadline, as this needs to run
perfectly within the next 24 hours.
|
by: prakash.mirji |
last post by:
I am using evaluation copy of RW 9.0 for porting one of C++
application on RHEL4 (x86 platform).
We are getting some issues into RW template classes. Please need
assistance on this issue.
Here is the problem:
Application is using below mentioned template class which is declared
at static in Engine.h
|
by: CuTe_Engineer |
last post by:
hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes
#these are the operations
+ = ,
- = ,
* = ,
1/ = only if 0 not in .
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |