What is the Best Way to Use Namespaces in C++?

  • Topic: Comp Sci 
  • Thread starter Thread starter Linda8888
  • Start date Start date
  • Tags Tags
    C++
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 1K views
Linda8888
Messages
7
Reaction score
1
Homework Statement
Explain what is wrong with the following code fragment(other than missing #include) and write down the change(s) that you will make to fix the problem(s).
Relevant Equations
I'm not sure what does "using" means at the second but I guess it is wrong.
C++:
using namespace std;
using vit = vector<string>::iterator;
void print(const vector<string>& s) {
  for(vit it = s.begin(); it != s.end(); ++it ) {
    count << *it << endl;
  }
}
 
Last edited by a moderator:
Physics news on Phys.org
It’s an abbreviation for the vector string iterator data type. It primarily saves the programmer from typing it over and over.
 
C++:
using namespace std;
using vit = vector<string>::iterator;
void print(vector<string>& s) {
  for(vit it = s.begin(); it != s.end(); ++it ) {
    count << *it << endl;
  }
}
 
  • Like
Likes   Reactions: Curtisc, jedishrfu and berkeman