Jump to content

[SOLVED] C++ Syntax Question?


Recommended Posts

Sorry to be asking so many questions tonight (knee deep in studying).  This'll be the last one I ask tonight.

This one is a "Which is better syntax" question.

 

string firstname;
cout << "What is your first name?";
std::getline(std::cin, firstname);
cin.ignore();

or

string firstname;
cout << "What is your first name?";
getline(cin, firstname);
cin.ignore();

 

The difference here is the std::getline can be used whether the namespace is included or not.  However the cin getline can't be called unless it is.

 

Out of these two which is the best method to get use to.  Using the std::funcname or just funcname.

Which is best overall because this'll be what I model my overall syntax ideas from.

Link to comment
Share on other sites

You can use infinite namespaces, or you can use 0.

 

The point of a namespace is kind of like a class in PHP.  It separates code based.

 

 

I generally go ahead and use the std namespace, but I don't usually use other ones at the same time.  If you're using two namespaces and they have functions with the same name, the compiler/linker will flip out.

 

 

So, to sum it up, I use the std namespace because I'm lazy and see no problems with it, but I generally avoid using other namespaces for 2 reasons:  the std namespace is the namespace in which most of the functions I use reside, and I don't like to use multiple namespaces, just in case.

 

 

 

 

I don't know if there's a 'standard' on namespaces though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.