2013-05-21 3 views
0

나는 최근에 유사한 코드를 발생?C++ 여기서 % 연산자는 무엇입니까?</p> <pre><code>std::string myString = "test"; boost::format fmt("%s"); fmt % myString; </code></pre> <p>여기하고있는 (초) % 연산자는 무엇입니까 :

편집 :

내가 최종 결과를 이해하지만, 내가 % 연산자는 다음과 같이 사용할 수있는 방법의 정의를 찾을 수 없습니다.

% 연산자의 의미가 정확히 무엇인지 설명하는 예제를 제공 할 수 있습니까?

+0

은 실제 대체를 수행합니다. – StoryTeller

+1

http://stackoverflow.com/questions/4421706/operator-overloading – StoryTeller

+0

연산자가 std :: string 또는 boost :: format 유형으로 재정의됩니까? – mclaassen

답변

3

최종 결과를 이해하지만 % 연산자를 어떻게 사용할 수 있는지에 대한 정의를 찾을 수 없습니다.

operator %은 오버로드 될 수 있습니다. Boost.Format does exactly that for its basic_format class :

당신이 fmt 유형 boost::basic_format<Ch>입니다 코드 fmt % value를 사용할 때마다이 멤버 함수가 호출됩니다
template<class T> 
basic_format& operator%(const T& x) 
    { return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); } 

.

관련 문제