길이로 정렬 된 파일에서 읽은 단어 목록을 만들려고합니다. 이를 위해 커스텀 비교기로 std :: set을 사용하려고합니다.std :: set와 함께 사용자 지정 비교기 사용
class Longer {
public:
bool operator() (const string& a, const string& b)
{ return a.size() > b.size();}
};
set<string, Longer> make_dictionary (const string& ifile){
// produces a map of words in 'ifile' sorted by their length
ifstream ifs {ifile};
if (!ifs) throw runtime_error ("couldn't open file for reading");
string word;
set<string, Longer> words;
while (ifs >> word){
strip(word);
tolower(word);
words.insert(word);
}
remove_plurals(words);
if (ifs.eof()){
return words;
}
else
throw runtime_error ("input failed");
}
이로부터, 나는 그 길이로 정렬 된 파일의 모든 단어 목록을 기대합니다. 대신, 입력에서 발생하는 각각의 길이 단 하나의 단어로, 매우 짧은 목록을 얻을 :
polynomially-decidable
complexity-theoretic
linearly-decidable
lexicographically
alternating-time
finite-variable
newenvironment
documentclass
binoppenalty
investigate
usepackage
corollary
latexsym
article
remark
logic
12pt
box
on
a
여기에 무슨 일이 일어나고 있는지의 어떤 생각?
는 [MCVE] (http://stackoverflow.com/help/mcve)로 프로그램 만 * 관련 * 부품을 게시하시기 바랍니다. – Csq