저는 Ubuntu의 CodeBlocks IDE에서 g ++을 사용하고 있습니다. STL과 C++의 일부를 처음 사용합니다.STL을 학습하는 동안의 몇 가지 문제
Q1은 : //
std::istream_iterator<std::string> begin (dictionaryFile);
std::istream_iterator<std::string> end;
std::vector< std::string> dictionary;
std::copy (begin, end, std::back_inserter (dictionary));
가 올바른 대답,하지만 난
std::istream_iterator<std::string> end();
컴파일러는 네 번째 줄에서 일치하는 함수 호출을 말한다에
std::istream_iterator<std::string> end;
를 변경하는 경우.
Q2 : // 미안 해요 firstLess1와 firstLess2 사이의 유일한 차이는 firstLess1가 PS에 선언되어 있다는 문제가 처음에게
struct PS : std::pair< std::string, std::string > {
PS();
static struct FirstLess: std::binary_function< PS, PS, bool> {
bool operator() (const PS & p, const PS & q) const {
return p.first < q.first;
}
} firstLess1; };
struct FirstLess: std::binary_function< PS, PS, bool> {
bool operator() (const PS & p, const PS & q) const {
return p.first < q.first;
}} firstLess2;
주를 취소하지 않았다. 나는 함수를 호출 할 때
는 :
k = std::find_if (j + 1, finis, std::not1 (std::bind1st (PS::firstLess1, *j)));
컴파일러는 'PS :: firstLess1에 정의되지 않은 참조'나에게 오류를했다. 다음 나는 그
k = std::find_if (j + 1, finis, std::not1 (std::bind1st (firstLess2, *j)));
로 변경이 컴파일을 통과시켰다.
더 이상, 프로그램의 다른 부분에, 나는 두
j = std::adjacent_find (j , finis, PS::firstLess1);
j = std::adjacent_find (j , finis, firstLess2);
을 사용하고 컴파일러는 나에게 오류를 준하지 않았다.
확인. 두 번째 질문을 해결하는 방법을 알아 냈습니다. (하지만 여전히 이유는 모르겠습니다.) 그냥 k = std :: find_if (j + 1, finis, std :: not1 (std :: bind1st (PS :: FirstLess(), * j))); OK 이거나 const PS :: FirstEqual PS :: firstEqual1 = PS :: FirstEqual()을 추가 할 수 있습니다. 선언 후. – user522829