now using cin a person can type some string into a chosen location.
Now I want to order this array so I've used
1 2 3 4 5 6 7 8 9 10 11 12 13
for (int i=0; i<=9; i++)
{
second[i] = first[i];
}
sort (second, second + 9);
for (int i=0; i<=9; i++)
{
cout << second[i] << endl;
}
So this array alphabetically orders the array of second. Which is fine. It works. But what I want to do is find the position in the first array that the text was entered and cout it.
For example
I enter "zenda" in location 7 of "first" array.
After first array gets coppied to second array. I want it to display
Zenda is in location 7.
...
Beta is in location 8.
@jilb
If it's a school assignment I'm sure skipping straight to the finish line of STLs would be discouraged. Though... Yes maps are delicious for direct LookUp.
Ok so, if I'm understanding this right you want to be able to sort the list of data but still retain where it was initially put into the array?
The only way to really retain that information is to create a variable for it.
1 2 3 4 5
struct Name
{
string m_name;
int m_position;
};
That way your input will always be linked to the original position. There are a ton of ways to go about what you're wanting and I'm *hoping* that I understood what you were wanting to do.
If it's a school assignment I'm sure skipping straight to the finish line of STLs would be discouraged.
True but most school assignments also discourage the use of std::sort as well. So not knowing the actual limits of the assignment who knows even structures may be off limits.?