//having std:: is not necessary when using namespace std globally
will save me a lot of time in the future... thanks
We meant that you shouldn't useusingnamespace std because it pollutes the global namespace. Either put std:: before each std thing you use or do this:
1 2 3 4 5 6
using std::cout;
using std::cin;
using std::endl;
using std::string;
//similar for any other std thing
These go after your #include statements. I prefer to have 20 of these rather than 200 std:: in the code. It is a user preference, so choose which you like.
I was hoping you would combine the 2 for loops together, they are not very logical at the moment. Look at this psuedo code:
1 2 3 4 5 6 7 8 9 10 11 12 13
for (int a = 0;a < 3;a++) {
cout << "Person Number "<< a+1 << endl;
cout<<"What is your name?"<<endl;
//get input
//store in array
cout<<"How old are you?"<<endl;
//get input
//store in array
}
Does this make more sense to you ?
With the algorithm stuff, I was wrong. push_back is related to lists without any further qualification. Algorithm is for things like find & sort etc. Sorry about that.
Edit:
Sort is the name of you r list variable, it doesn't sort the list.
you guys are right thanks
TheIdeasMan can you explain why the usingnamespace std pollutes the namespace??
no problem about the algorithm thanks for mentioning it
I do not combine them because that is how my boss ask the code to be...
guess just for the sake of practicing for loops...
but yes it makes a lot more sense I know...
It pollutes the global namespace because there is heaps & heaps of stuff in std. Doing things the way we have suggested makes things easier for the compiler.
I am not sure why they did it that way - could they have had individual namespaces for string, vector, list etc?
Going back to algorithms, looks as though you do need the sort algorithm !!
could they have had individual namespaces for string, vector, list etc
That would be silly. Those are all part of the standard library, aka std namespace. Shouldn't ever cause you a problem unless you stick it in the global scope.
explain why the using namespace std pollutes the namespace
For example, if you're using another library that has it's own version of a vector with some extra functionality or something, if you stick the std namespace and the library namespace all in global scope, when you try to use a vector your compiler won't have any idea which one you mean.
ohh ok guys.. that makes sense... thanks
I just found another problem....
when I run the program... this runs normally until it the end where it should give the oldest age... what happens... is that I get a bunch of characters... and obviously I do not get the oldest person...
I edited my post, so you might not have seen this part:
Edit:
Sort is the name of you r list variable, it doesn't sort the list.
So Sort is rather bad name for the variable. Naming is important - bad naming can cause a lot of confusion & errors.
That is why you need the algorithm header, because now you need the sort algorithm. Read the reference on this site - go to the reference section on the top left of this page. Also google.