what's wrong with my codes?

Joined
May 21, 2007
Messages
1
Reaction score
0
I use visual .net C++ to compile my source file,but I got some errors like

e:\project\test\test3\test3\Source1.cpp(6): error C2143: syntax error : missing ';' before '<'
e:\project\test\test3\test3\Source1.cpp(5): error C2143: syntax error : missing ';' before '<'
e:\project\test\test3\test3\Source1.cpp(5): error C2501: 'vector' : missing storage-class or type specifiers
e:\project\test\test3\test3\Source1.cpp(6): error C2501: 'vector' : missing storage-class or type specifiers
e:\project\test\test3\test3\Source1.cpp(6): error C2086: 'int vector' : redefinition
e:\project\test\test3\test3\Source1.cpp(6): error C2039: 'iterator' : is not a member of 'operator``global namespace'''
e:\project\test\test3\test3\Source1.cpp(10): error C2065: 'first' : undeclared identifier
e:\project\test\test3\test3\Source1.cpp(10): error C2065: 'v' : undeclared identifier
e:\project\test\test3\test3\Source1.cpp(10): error C2228: left of '.insert' must have class/struct/union type
type is ''unknown-type''
e:\project\test\test3\test3\Source1.cpp(10): error C3861: 'first': identifier not found, even with argument-dependent lookup
e:\project\test\test3\test3\Source1.cpp(13): error C2228: left of '.end' must have class/struct/union type
e:\project\test\test3\test3\Source1.cpp(13): error C3861: 'first': identifier not found, even with argument-dependent lookup
e:\project\test\test3\test3\Source1.cpp(13): error C3861: 'v': identifier not found, even with argument-dependent lookup
e:\project\test\test3\test3\Source1.cpp(13): fatal error C1903: unable to recover from previous error(s); stopping compilation





The following are my source codes:

#include <vector>
#include <list>
#include <deque>

vector<int> v;
vector<int>::iterator first = v.begin(),
last = v.end(); // cache end iterator
void main(void)
{
first = v.insert(first, 42);

// safer: recalculate end on each trip whenever the loop adds/erases elements
while (first != v.end()) {
// do some processing
first = v.insert(first, 42); // insert new value
++first; // advance first just past the element we added
}
}

What's wrong with my codes?
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top