mingw 编译器错误
第一次尝试在不使用 Visual Studio 的情况下编译一些代码。安装mingw并设置环境路径变量。然后尝试编译此代码:
#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;
}
通过打开 cmd shell,转到单个源文件的目录并键入:
g++ main.cpp
但我收到很多错误消息,如下所示:
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
我在这里遗漏了一些非常明显的东西吗?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
把它变成:
Turn it into:
您在向量定义和 size_type (及其后面的迭代器)之间缺少 :: 运算符。
You are missing :: operator between the vector definition and size_type (and iterator after it).
typedef std::vector::size_type
应该是typedef std::vector::size_type size;
等。typedef std::vector<int>::size_type
should betypedef std::vector<int>::size_type size;
etc.