[問題] STL sort
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev C++
問題(Question):
使用sort()一直有錯誤
-----------------------------------------------------------------------------
class Person
{ ...
private:string name;
...
}
class PeopleList
{ public:
...
bool PersonComp(Person&,Person&) const; //compare two people's names
void Gifting(char*); //gifting operation
...
private:int numP; //number of people
vector<Person> plistI , plistF ; //people list in vector
//type, initial and final
}
...
bool PeopleList::PersonComp(Person& p1,Person& p2) const
{ return ( p1.name < p2.name ); //我想用名字去做排序
}
void PeopleList::Gifting(char* ifile)
{ ifstream ifs(ifile);
int temp_numP;
ifs>>temp_numP;
for ( int i=1 ; i<=temp_numP ; i++ )
{ string temp_name;
ifs>>temp_name;
Person *p=new Person(temp_name);
Add(*p);
}
//上面是從檔案裡面先讀取人數,再讀取名字
plistF=plistI; //copy vector
std::sort( plistF.begin() , plistF.end() , PersonComp );
//sorting by name
//問題就是這個sort,我想練習用STL來做
}
------------------------------------------------------------------------
std::有加沒加都會錯 有加的時候錯誤碼很多行 沒加反而只有三行(同學叫我加加看的)
程式碼(Code):(請善用置底文網頁, 記得排版)
這邊有完整的程式碼
http://codepad.org/LY73NqXU
補充說明(Supplement):
這程式還沒打完 我是邊做邊檢察這樣
假設讀取的檔案是這樣:
5
dave
laura
owen
vick
amr
就是有五個人 然後接著讀取他們的名字...
不好意思 第一次在這發文 格式有錯我可以再改
麻煩大家幫忙不才解惑一下 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.5.154
推
02/28 23:13, , 1F
02/28 23:13, 1F
推
02/28 23:15, , 2F
02/28 23:15, 2F
→
02/28 23:25, , 3F
02/28 23:25, 3F
→
02/28 23:26, , 4F
02/28 23:26, 4F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
問題
2
4