chuyler1
asked on
Vector templates not working on Solaris (Sun ONE Studio 8).
I just upgraded to Sun One Studio 8 Compiler Colleciton and I can't seem to get vector working. Here is a little test program:
#include <vector>
int main() {
printf ("Just testing the vector include...\n");
vector<int> v;
return 0;
}
And here is what happens:
[root@usfrssa9 vector]# uname -a
SunOS usfrssa9 5.9 Generic sun4u sparc SUNW,Sun-Blade-100
[root@usfrssa9 vector]# /opt/SUNWspro/bin/CC -V
CC: Sun C++ 5.5 2003/03/12
[root@usfrssa9 vector]# /opt/SUNWspro/bin/CC vector.cpp
"vector.cpp", line 5: Error: vector is not defined.
"vector.cpp", line 5: Error: Badly formed expression.
2 Error(s) detected.
Am I missing something? I looked for the vector include file and found two:
[root@usfrssa9 vector]# find /usr/include /opt/SUNWspro -name vector -print
/opt/SUNWspro/prod/include /CC/Cstd/v ector
/opt/SUNWspro/prod/include /CC/stlpor t4/vector
I tried adding each of these to the include path but that didn't help.
#include <vector>
int main() {
printf ("Just testing the vector include...\n");
vector<int> v;
return 0;
}
And here is what happens:
[root@usfrssa9 vector]# uname -a
SunOS usfrssa9 5.9 Generic sun4u sparc SUNW,Sun-Blade-100
[root@usfrssa9 vector]# /opt/SUNWspro/bin/CC -V
CC: Sun C++ 5.5 2003/03/12
[root@usfrssa9 vector]# /opt/SUNWspro/bin/CC vector.cpp
"vector.cpp", line 5: Error: vector is not defined.
"vector.cpp", line 5: Error: Badly formed expression.
2 Error(s) detected.
Am I missing something? I looked for the vector include file and found two:
[root@usfrssa9 vector]# find /usr/include /opt/SUNWspro -name vector -print
/opt/SUNWspro/prod/include
/opt/SUNWspro/prod/include
I tried adding each of these to the include path but that didn't help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, the 1st approach will save a lot more typing :o)
ASKER
Ok, that worked! Why is it that the man page posts an example without doing this?
EXAMPLE
//
// vector.cpp
//
#include <vector>
#include <iostream>
ostream& operator<< (ostream& out,
const vector<int, allocator>& v)
{
copy(v.begin(),v.end(),ost ream_itera tor<int,ch ar>(out,"
"));
return out;
}
int main(void)
{
// create a vector of doubles
vector<int> vi;
int i;
for(i = 0; i < 10; ++i) {
// insert values before the beginning
vi.insert(vi.begin(), i);
}
// print out the vector
cout << vi << endl;
// now let's erase half of the elements
int half = vi.size() >> 1;
for(i = 0; i < half; ++i) {
vi.erase(vi.begin());
}
// print ir out again
cout << vi << endl;
return 0;
}
EXAMPLE
//
// vector.cpp
//
#include <vector>
#include <iostream>
ostream& operator<< (ostream& out,
const vector<int, allocator>& v)
{
copy(v.begin(),v.end(),ost
"));
return out;
}
int main(void)
{
// create a vector of doubles
vector<int> vi;
int i;
for(i = 0; i < 10; ++i) {
// insert values before the beginning
vi.insert(vi.begin(), i);
}
// print out the vector
cout << vi << endl;
// now let's erase half of the elements
int half = vi.size() >> 1;
for(i = 0; i < half; ++i) {
vi.erase(vi.begin());
}
// print ir out again
cout << vi << endl;
return 0;
}
Good question :o)
Either the man page is erroneos or simply outdated - maybe it was created before the C++ standard has been finalized...
Either the man page is erroneos or simply outdated - maybe it was created before the C++ standard has been finalized...