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
https://forums.phpfreaks.com/topic/142214-solved-c-syntax-question/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.