c++compiler-errorsmingw

mingw compiler errors


First attempt at compiling some code without using Visual Studio. Installed mingw and set the environment path variable. Then tried to compile this code:

#include <iostream>
#include <vector>

int main() {
typedef std::vector<int> Container;
typedef std::vector<int>size_type size;
typedef std::vector<int>iterator iter;

Container container; 

for (size i = 0; i != 1000000; ++i) {
container.push_back(i);
}

for (iter i = container.begin(); i != container.end(); ++i) {
std::cout << *i << " " << std::endl;
}

system("PAUSE");
return 0;
}

By opening up a cmd shell, going to directory of single source file and typing:

g++ main.cpp

But i get a lot of error messages as follows:

main.cpp: In function 'int main()':
main.cpp:6:35: error: expected initializer before 'size'
main.cpp:7:34: error: expected initializer before 'iter'
main.cpp:11:6: error: 'size' was not declared in this scope
main.cpp:11:11: error: expected ';' before 'i'
main.cpp:11:18: error: 'i' was not declared in this scope
main.cpp:15:6: error: 'iter' was not declared in this scope
main.cpp:15:11: error: expected ';' before 'i'
main.cpp:15:34: error: 'i' was not declared in this scope
main.cpp:19:15: error: 'system' was not declared in this scope

Am i missing something painfully obvious here? Thanks.


Solution

  • typedef std::vector<int>size_type size;
    typedef std::vector<int>iterator iter;
    

    Turn it into:

    typedef std::vector<int>::size_type size;
    typedef std::vector<int>::iterator iter;