Question for "using" in C++

  • Comp Sci
  • Thread starter Linda8888
  • Start date
  • #1
Linda8888
7
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 ) {
    cout << *it << endl;
  }
}
 
Last edited by a moderator:

Answers and Replies

  • #2
14,297
8,343
It’s an abbreviation for the vector string iterator data type. It primarily saves the programmer from typing it over and over.
 
  • #3
2,813
605
C++:
using namespace std;
using vit = vector<string>::iterator;
void print(vector<string>& s) {
  for(vit it = s.begin(); it != s.end(); ++it ) {
    cout << *it << endl;
  }
}
 
  • Like
Likes Curtisc, jedishrfu and berkeman
  • #4
14,297
8,343
Thanks @ShayanJ I fixed the OP’s post as well.
 

Suggested for: Question for "using" in C++

Replies
42
Views
690
Replies
1
Views
331
Replies
2
Views
412
  • Last Post
Replies
2
Views
13
Replies
17
Views
728
  • Last Post
Replies
2
Views
788
  • Last Post
Replies
3
Views
81
Replies
4
Views
952
  • Last Post
Replies
12
Views
587
Replies
0
Views
473
Top