I finished my lab problem, but I have a quick question to fix the end. I have a vector in the function that needs to be returned to main so I can output the elements of the vector. I put return a; at the end of the function since a is the name of the vector in the function but I'm getting an error.
*Where it says "cout << the names are " should be in the main but I can't figure out what to put in the return. *I also put return 0 because it was the only way I had the whole program working since the output is also in the function, but I need it back in main and change the return 0; Sorry if this is a bad question I'm still learning, thanks.
string switching(vector<string> a, int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
swap(a[i], a[j]);
}
}
}
cout << "The order of names are...\n";
for (int i = 0; i < n; i++) {
cout << a[i] << "\n";
}
return 0;
}
vector<string>instead thenreturn a;would work.return a;gives you an error becauseaisvector<string>but you put the return type asstring. How would you fix that?