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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top