Click to See Complete Forum and Search --> : Meeting troubles when compiling simple STL program.
George2
February 3rd, 2003, 10:32 PM
Hi, everyone!
I meet with the following trouble when compiling the
following simple STL program.
The error message is, ostream_iterator undeclared.
My IDE is VC 6.0.
Here are the source codes,
--------
#include "iterator"
#include "iostream"
void main()
{
ostream_iterator<int> r (cout);
*r = 0;
}
--------
Thanks in advance,
George
SeventhStar
February 4th, 2003, 02:27 AM
dont forget to write
either
std:: ostream_iterator r;
or
using namespace std;
aafter the #includes
Andreas Masur
February 4th, 2003, 03:06 AM
Everything of the STL is declared within the namespace 'std'. Therefore you need to map the namespace to your application as mentioned.
The following shows you the four different methods to map a namespace...
// Using the full member name, including the namespace it belongs to:
std::cout << "Hello World";
// By taking advantage of Using-Declarations:
using std::cout; // This declares cout in the current
// scope as synonym for std::cout
cout << "Hello World";
// By taking advantage of Using-Directives:
using namespace std; // Which specifies that the current
// scope can refer to names in the
// 'std' namespace without using
// full qualifiers. This is mostly
// used when porting legacy code.
cout << "Hello World";
// Using aliases:
namespace X
{
namespace Y
{
class Z { ... };
}
}
X::Y::Z // The full qualifier for 'Z' is
// 'X::Y::Z'
namespace w = X::Y; // This declares 'w' as an alias for
// namespace 'X::Y'
w::Z // Access 'Z' using 'w::Z'
George2
February 4th, 2003, 03:14 AM
Thanks!
Originally posted by Andreas Masur
Everything of the STL is declared within the namespace 'std'. Therefore you need to map the namespace to your application as mentioned.
The following shows you the four different methods to map a namespace...
// Using the full member name, including the namespace it belongs to:
std::cout << "Hello World";
// By taking advantage of Using-Declarations:
using std::cout; // This declares cout in the current
// scope as synonym for std::cout
cout << "Hello World";
// By taking advantage of Using-Directives:
using namespace std; // Which specifies that the current
// scope can refer to names in the
// 'std' namespace without using
// full qualifiers. This is mostly
// used when porting legacy code.
cout << "Hello World";
// Using aliases:
namespace X
{
namespace Y
{
class Z { ... };
}
}
X::Y::Z // The full qualifier for 'Z' is
// 'X::Y::Z'
namespace w = X::Y; // This declares 'w' as an alias for
// namespace 'X::Y'
w::Z // Access 'Z' using 'w::Z'
George2
February 4th, 2003, 03:16 AM
Originally posted by Andreas Masur
Everything of the STL is declared within the namespace 'std'. Therefore you need to map the namespace to your application as mentioned.
The following shows you the four different methods to map a namespace...
// Using the full member name, including the namespace it belongs to:
std::cout << "Hello World";
// By taking advantage of Using-Declarations:
using std::cout; // This declares cout in the current
// scope as synonym for std::cout
cout << "Hello World";
// By taking advantage of Using-Directives:
using namespace std; // Which specifies that the current
// scope can refer to names in the
// 'std' namespace without using
// full qualifiers. This is mostly
// used when porting legacy code.
cout << "Hello World";
// Using aliases:
namespace X
{
namespace Y
{
class Z { ... };
}
}
X::Y::Z // The full qualifier for 'Z' is
// 'X::Y::Z'
namespace w = X::Y; // This declares 'w' as an alias for
// namespace 'X::Y'
w::Z // Access 'Z' using 'w::Z'
George2
February 4th, 2003, 03:18 AM
Thanks, SeventhStar buddies!
George
Originally posted by SeventhStar
dont forget to write
either
std:: ostream_iterator r;
or
using namespace std;
aafter the #includes
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.