So, I have the following in a specification file
#include <string>
#include <fstream>
using namespace std:
class MyStuff
{
private:
string name;
fstream file;
// other stuff
public:
void setName(string);
}
I also have in the implementation file
#include "MyStuff.h"
using namespace std;
void MyStuff::setName(string name);
{
name = name
}
and in the program file I have...
#include <iostream>
#include <string>
using namespace std;
void main()
{
string name;
MyStuff Stuff;
cout << "Enter Your Name: ";
getline(cin, name);
Stuff.setName(name);
}
And I'm gathering that applying "using namespace std;" in a header file is a no-no, and that to fully qualify is the "better" practice; such as std::cout << stuff << endl;
It is my understanding that in order to use a string, it must have the std namespace. Is that true?
If so, in the header file, is more "pure/clean" to do it as...
#include <string>
class MyStuff
{
std::string name;
}
And, as I understand it currently, using namespace std; across all three files, specification, implementation, and program, essentially layers the three namespaces on top of each other, so if I separately declare string name;
within each of the files, the compiler will not know which goes to what. Is that true?
I generally understand that being clear is a "good" thing to do, I am however a little unclear on the specificity of how, and I'm most interested in the deeper "why" that underlies it all.
So my direct question is, in my example provided, what is the "clearest" way to describe the function both for the compiler and for industry "standard"? And, can you direct me to resources that more clearly delineate the reasoning and practical implementation of namespaces.
Question&Answers:
os