Hello,
Here is an example of my problem:
When I try to compile it I get such error:Code:#include <vector> #include <cstdio> using namespace std; int main() { vector<int> *v; int a; scanf("%d", &a); v=new vector<int>(a); if(a<2) return -1; v[1]=1; return 0; }
Without line with v[1]=1; it compiles but I don't know what I do wrong. I have ever example of it in Stroustrup's book but I don't know. I just want to have an outcome similar to$ g++ test.cpp
test.cpp: In function `int main()':
test.cpp:15: error: no match for 'operator=' in '*(v + 12u) = 1'
/usr/include/c++/3.4/bits/vector.tcc:131: note: candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>:perator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int, _Alloc = std::allocator<int>]
$
vector<int> v(a);
but I need v to have global so I have to
vector<int> *v;
and then in main() to create it with 'a' amount.
Can anyone help me?
Regards.