Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Vector templates not working on Solaris (Sun ONE Studio 8).

Posted on 2004-09-03
4
383 Views
Last Modified: 2013-12-26
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/vector
/opt/SUNWspro/prod/include/CC/stlport4/vector

I tried adding each of these to the include path but that didn't help.
0
Comment
Question by:chuyler1
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
ID: 11973370
You need to specify the 'std' namespace or explicitly point out that you're referring to 'std::vector', e.g.

#include <vector>
using namespace std;

int main() {
        printf ("Just testing the vector include...\n");
        vector<int> v;
        return 0;
}
or

#include <vector>

int main() {
        printf ("Just testing the vector include...\n");
        std::vector<int> v;
        return 0;
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 11973379
BTW, the 1st approach will save a lot more typing :o)
0
 

Author Comment

by:chuyler1
ID: 11973443
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(),ostream_iterator<int,char>(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;
      }
0
 
LVL 86

Expert Comment

by:jkr
ID: 11973510
Good question :o)

Either the man page is erroneos or simply outdated - maybe it was created before the C++ standard has been finalized...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 51
Adapt this command to show who installed 29 111
Execute multiple curl cmds with sleep and send output to file 10 104
how to split multiple lines delimiter : 8 109
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question