473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

std::cout vs cout

Pmb
I've noticed a lot of people preferring std::cout over cout. May I ask why
you prefer one over the other?

thanks

Pmb
Jul 22 '05 #1
2 3280
Pmb wrote:
I've noticed a lot of people preferring std::cout over cout. May I ask why
you prefer one over the other?


'cout' is half as short to type. OTOH, to use it you need to declare
the name 'std::cout' as _used_ in the current scope, which is commonly
done by means of 'using' declaration, which in itself a kind of blanket
statement. Often, you might not want to bring the name into the scope
and instead use the "full" form. You know, like calling somebody "Mr.
Firstname Lastname" instead of "sir".

I prefer using most of standard types and objects with the namespace
prefix, unless I am being lazy, in which case I usually just say 'using
namespace std;'.

Victor
Jul 22 '05 #2
On Wed, 02 Jun 2004 10:30:45 -0400, Victor Bazarov
<v.********@comAcast.net> wrote:
Pmb wrote:
I've noticed a lot of people preferring std::cout over cout. May I ask why
you prefer one over the other?
'cout' is half as short to type. OTOH, to use it you need to declare
the name 'std::cout' as _used_ in the current scope, which is commonly
done by means of 'using' declaration, which in itself a kind of blanket
statement. Often, you might not want to bring the name into the scope
and instead use the "full" form. You know, like calling somebody "Mr.
Firstname Lastname" instead of "sir".

I prefer using most of standard types and objects with the namespace
prefix, unless I am being lazy, in which case I usually just say 'using
namespace std;'.


The "middle ground" is to bring the names you want into scope via using
/declarations/ rather than the directive:

using std::cout;
using std::endl;

Following the most recent discussion of the perils of the using directive,
I've edited my default testing template so that it contains the two
declarations above (bringing in the identifiers I most commonly use in my
little hack test programs), in place of my original
using namespace std;
directive at namespace scope (which, as it continuously gets pointed out,
is evil).
-leor

Victor


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3

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

Similar topics

12
by: Minti | last post by:
Is std::cout slower than printf When we call printf e.g. in printf(20 format conversion specifications, 20 arguments); Is it faster than the std::cout << { 20 redirections to the output...
6
by: clilley | last post by:
The following code causes a segmentation fault on DEC Tru64: foo.cc (built into libFoo.so) //--------------------------- include <iostream> bool createFoo() { std::cout << "createFoo" <<...
3
by: Jason Heyes | last post by:
I have a function that reads tags. The function prints any failures it encounters to std::cout. std::istream &read_tag(std::istream &is, std::string &tag) { std::string s; if (!(is >> s)) {...
6
by: nish.parikh | last post by:
Hi, I am using std::cout to print a char pointer that is NULL. Subsequent calls to std::cout dont print anything. Is this the expected behavior? example: #include <iostream> int main( int...
19
by: Dancefire | last post by:
Hi, everyone It might be a simple question, but I really don't know the answer. char c = '1'; cout << c; The above code will only output a '1' rather than 0x31; If I use int cast, it can...
6
by: Roger | last post by:
Hello, I'm pretty new to C++ programming, and I'm teaching myself the language using various sources. This sounds stupid, but I am really confused on this... I was wondering why we have to write...
5
by: wongjoekmeu | last post by:
Dear All, I have written a small program to read in from console a user string. I wanted to be able to read in a string containing of all sorts of characters untill the user press enter. I have to...
11
by: Adrian | last post by:
Is it possible to save a copy of cout the same way you can save a copy of stdout in C (I know C version is portable, but unix portable is good enough for me). I have to use a library which...
58
by: Mark Casternoff | last post by:
I'm getting back into C++ after a long hiatus (they didn't have namespaces back then). I know this question is completely subjective, but I'd be interested in hearing which is the "better"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...
0
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,...
0
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...

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.