2번째 stl 질문입니다.

nayana의 이미지

vc++ 에서는 아무 이상없이 돌아가는데..
g++ 에서는 에러가 납니다.
제가 주로 이용하는 컴파일러가 g++ ???
질문을 드립니다.
소스는

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <vector>
#include <algorithm>

int main ( void )
{
	const int SIZE = 6;
	int       array[ SIZE ] = { 1, 2, 3, 4, 5, 6 };

	std::vector< int >			 integers( array, array + SIZE );
	std::ostream_iterator< int > output( cout, " " );

	cout << "Vector integers contains: ";
	std::copy( integers.begin(), integers.end(), output );

	cout << "\nFirst element of integers: " << integers.front()
		 << "\nLast element of integers: " << integers.back();
	
	integers[ 0 ]    = 7;
	integers.at( 2 ) = 10;

	integers.insert( integers.begin() + 1, 22 );

	cout << "\n\nContents of vector integers after changes: ";
	std::copy( integers.begin(), integers.end(), output );

	try{
		integers.at( 100 ) = 777;
	}

	catch( std::out_of_range outOfRange )
	{
		cout << "\n\nException: " << outOfRange.what();
	}

	integers.erase( integers.begin() );
	cout << "\n\nVector integers after erasing first element: ";
	std::copy( integers.begin(), integers.end(), output );

	integers.erase( integers.begin(), integers.end() );
	cout << "\nAfter erasing all elements, vector integers "
		<< ( integers.empty() ? "is" : "is not" ) << " empty";
	
	integers.insert( integers.begin(), array, array + SIZE );
	cout << "\n\nContents of vector integers begore clear: ";
	std::copy( integers.begin(), integers.end(), output );

	integers.clear();
	cout << "\nAfter clear, vector integers "
		<< ( integers.empty() ? "is" : "is not" ) << "empty";

	cout << endl;

	return 0;
}

에러는 다음과 같습니다.

fig.cpp: In function `int main()':
fig.cpp:16: `ostream_iterator' undeclared in namespace `std'
fig.cpp:16: parse error before `>' token
fig.cpp:19: `output' undeclared (first use this function)
fig.cpp:19: (Each undeclared identifier is reported only once for each function
   it appears in.)
fig.cpp:36: parse error before `)' token
fig.cpp: At global scope:
fig.cpp:41: syntax error before `.' token
fig.cpp:42: syntax error before `<<' token
fig.cpp:43: `integers' was not declared in this scope
fig.cpp:43: `integers' was not declared in this scope
fig.cpp:43: ISO C++ forbids declaration of `copy' with no type
fig.cpp:43: `int std::copy' redeclared as different kind of symbol
/usr/include/c++/3.2.2/bits/stl_algobase.h:342: previous declaration of `
   template<class _InputIter, class _OutputIter> _OutputIter
   std::copy(_InputIter, _InputIter, _OutputIter)'
fig.cpp:43: initializer list being treated as compound expression
fig.cpp:45: syntax error before `.' token
fig.cpp:46: syntax error before `<<' token
fig.cpp:49: syntax error before `.' token
fig.cpp:50: syntax error before `<<' token
fig.cpp:51: `integers' was not declared in this scope
fig.cpp:51: `integers' was not declared in this scope
fig.cpp:51: ISO C++ forbids declaration of `copy' with no type
fig.cpp:51: `int std::copy' redeclared as different kind of symbol
/usr/include/c++/3.2.2/bits/stl_algobase.h:342: previous declaration of `
   template<class _InputIter, class _OutputIter> _OutputIter
   std::copy(_InputIter, _InputIter, _OutputIter)'
fig.cpp:51: initializer list being treated as compound expression
fig.cpp:53: syntax error before `.' token
fig.cpp:54: syntax error before `<<' token
fig.cpp:57: syntax error before `<<' token
익명 사용자의 이미지

#include <iterator>
#include <stdexcept>

추가 하시면 됩니다..

nayana의 이미지

답변 감사드립니다.

freezm7의 이미지

Anonymous wrote:
#include <iterator>
#include <stdexcept>

추가 하시면 됩니다..

손님으로 답글을 남기시니...

미야모토 무사시의 도장 깨기가 갑자기 떠오르네요 ㅎㅎ

얼마 전, 바람의 파이터를 봐선가...

잡담이었습니다. (자유 게시판 아니지만 용서를...)

즐겁게 살아 볼까나~*