compiles in dev c++ but not in ms vc++ 6.00

hi again I did this in dev c++ works fine .. this was actually a converted program from vector arrays then to pointers I used this line to convert vector arrays to work with pointers as I saw this example.. it worked

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;
   vector<int> v;
   v.push_back( 11 );
   v.push_back( 22 );

   vector<int>::pointer ptr = &v[0];
   cout << *ptr << endl;
   ptr++;
   cout << *ptr << endl;
   *ptr = 44;
   cout << *ptr << endl;
system("Pause");
return 0;
}


Now I tried it on ms visual c++ 6.0 it gives me this error

pointer' : is not a member of 'vector<int,class std::allocator<int> >

So I m trying to hand trace and understand compiler differences.. and maybe I did the pointers syntax wrong.. I think
Question is why did it work in dev c++ and not in ms vc++ 6.00?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
#include<vector>

using namespace std;
void showData(vector<int>);
void selectionSort(vector<int>&,int);
void sortedShowData(vector<int>&,int);

double findMedian(vector<int>&,int);

int main ()
{
vector<int> values;
int Size;
int mid=0;
double median=0.0;
cout<<"Input the size of the array:";
cin>>Size;
for (int counter=0;counter<Size;counter++)
  { 
  int no;
    cout<<"Value ["<<(counter+1)<<"]:";
      cin>>no;
        values.push_back(no);
    }
    
  cout<<endl;
  cout<<"User Input..\n";
  showData(values);
  cout<<endl; 
  selectionSort(values,Size);
  cout<<endl;
  cout<<"Sorted..."<<endl;
  sortedShowData(values,Size);
  cout<<endl;
  
  median=findMedian(values, Size);
  cout<<"Median:"<<median <<endl;
  system("pause");

return 0;
}

void showData(vector<int> vect)
{
     vector<int>::pointer sec_ptr = &vect[0];
     for(int count=0; count<vect.size();count++)
     cout<<*(sec_ptr+count)<<" ";
}
void selectionSort(vector<int>& ArrayOne,int)
{    
   vector<int>::pointer thrd_ptr = &ArrayOne[0];
    int startScan, minIndex, minValue;
    int size=ArrayOne.size();
     for (int startScan=0; startScan<size-1;startScan++)
    {
     minIndex =startScan;
     minValue = *(thrd_ptr+startScan);
     for (int index =startScan+1; index<size;index++)
     {
         if (*(thrd_ptr+index)<minValue)
            {
             minValue =*(thrd_ptr+index);
             minIndex=index;
             }
      }
             *(thrd_ptr+minIndex)=*(thrd_ptr+startScan);
             *(thrd_ptr+startScan)=minValue;
    }        

}

void sortedShowData(vector<int>& ArraySort, int size)
{   
    vector<int>::pointer ptr = &ArraySort[0];
     size=ArraySort.size();
     for (int ctr=0;ctr<size; ctr++)
     cout<<*(ptr+ctr)<<" ";
}
double findMedian(vector<int>& ArraySet,int size)
{     
       vector<int>::pointer fourth_ptr = &ArraySet[0];
       size=ArraySet.size();
       double median = 0.0;
	   int mid = 0;
    
       	if(size % 2 == 0)
	    {
		  mid = (size/2);
		   median = ((*(fourth_ptr+mid) + *(fourth_ptr+(mid -1))) / 2.0);
        }
	    else
	     {
		mid = (size / 2);
		median = *(fourth_ptr+mid);
        	}
	return median;
 }
vector<int>::pointer ptr = &v[0];
What's up with this convoluted syntax?
Write int* ptr=&v[0]; instead.

VC6 is not standard-compliant and outdated, do not use it.
Dev-C++ and the version of MinGW that comes with it is outdated as well, don't use it either.
Get yourself a copy of the Code::Blocks+MinGW bundle or a recent version of Visual Studio Express.
Because the two compilers have different levels of supporting the C++ standard.
Last edited on

You guys rock.... Athar.. thanks for the comment I like that..
convoluted syntax... Man.. this is the best forum ever.. that of course.. I have
not tried others...

and vlad thanks unfortunately right now Schools and the stiff academia do not understand what compiling is so they use outmoded versions but hey it works .. but thank you both...

Long live Programmers!!! old and young!!!
Topic archived. No new replies allowed.