Hi, im currently facing the sort first name according to the alphabets at Edit() part. i want my name show and sort by first name according to alphabets. need somebody to teach me how to fix this?? this is part of my code.
void PhoneBook::ReadFromFile()
{
ifstream studentFile("D:\\phonebook.txt");
currentIndex = -1;
if (studentFile.is_open()) { //checks to see if file is good and that it opened correctly
while(!studentFile.eof()) { //while we are not at the end of the file
string mstring;
getline(studentFile, mstring); // Saves the line in myString
char *myString = (char*)mstring.c_str();
if(mstring!="")
{
currentIndex++;
int i = 0;
int j = 0;
while(myString[i] != ';')
{
contact[currentIndex].first[j] = myString[i];
j++;
i++;
}
First and foremost, use code tags. Most of us won't read a post if the code is not properly formatted using code tags.
Second, what does Edit() have to do with sorting? I just don't get it. If what you want is to keep an array sorted after the sort key is potentially changed (in Edit()), then I guess all you have to do is either re-insert the element (more complex but more efficient), or simply call your sort() routine (I am guessing you have a sort routine somewhere; I didn't read the code because it is not formatted).
If what you need is a sorting algorithm, you can check Wikipedia for all different available methods, then pick one and code it. Alternatively, if you are allowed, you could use std::sort(), available in the <algorithm> header file.