안녕하세요 .obj 모델 파서를 작성하는 중 일부 코드에 문제가 있습니다.std :: copy를 사용할 때 오류가 발생했습니다.
V -5.000000 -1.000000 1.000000
그런 다음 문자열을 가져옵니다
std::istringstream iss(line.substr(1));
std::copy(
std::istream_iterator<float>(iss),
std::istream_iterator<float>(),
std::back_inserter<std::vector<float>>(model.chunks.back().vectices)
);
그것은 기본적으로이 같은 인수로 전달 된 문자열을 복용 : 는 여기에 문제를 일으키는 코드입니다 그것으로부터 단지 이것 만 남았습니다 :
-5.000000-1.0 마지막으로 00000 1.000000
나는 표준 : : 사본을 사용하여 문자열 내에서 각 숫자 세트를 얻을 :
정점 [0] = -5.000000
: 정점 [2] 1.000000
정점 [1] = -1.000000
을 = 어쨌든 여기에 주요 문제는이 코드 줄에서 오류를 얻고 있다는 것입니다
std::back_inserter<std::vector<float>>(model.chunks.back().vectices));
"예상 토큰 ';' float을 얻었습니다. "내 코드는 여전히 컴파일되고 실행됩니다.
비록 그 코드의 수레를 std :: string의 것으로 바꾸더라도 나는 더 이상 오류를 얻지 못합니다.
std::copy(
std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>(),
std::back_inserter<std::vector<std::string>>(model.chunks.back().vectices)
);
Qt Creator를 사용하고있어서 IDE 오류 일 수 있습니까? 어떤 도움이라도 대단히 감사하겠습니다!
std :: back_inserter는 인수에서 유형을 추론 할 수 있습니다. – ForEveR
'std :: back_inserter (model.chunks.back(). vectices)'를 써서 컴파일러가 형식 인자를 추론하도록하지 않는 이유는 무엇입니까? – Nawaz
음 ... 그런 생각을하지 못했습니다. 또한 적은 코드가 필요합니다. 팁 고마워! – luveti