|I just thought that was the whole point of the ' using namespace std' so I did not have to type that every time. I'm not sure if there is just something I am doing wrong concerning this ...|
It's best practise to actually put
before each std thing. The whole point of namespaces is to keep identifiers separate form each other. When one has
using namespace std
, it brings in heaps of things from the STL, increasing the chance of clashes with variable or function identifiers. Here is a list of the current std symbols that come into scope when one has sing namespace std (providing the appropriate header file is included): https://en.cppreference.com/w/cpp/symbol_index
. Who knows what identifiers may be added in the future, breaking your code.
For example there is a
in the iostream header, if one used
as a variable name, that causes a clash which can hard to spot.
One does get used to the extra typing. The other thing to do, is setup the IDE to do code snippets: have mnemonics like str
say, once you type that, the editor replaces it with
is explicit :
is what it is, not
or some other
It's a good idea to put your own code into it's own namespace.
|" String does not name a type' |
Are you sure you didn't type String instead of string ? If String appears in the error message you must have.