最近想开始学习stl,但是利用VC6.0进行编译的话,总会出现很多警告,而换用VS2005之类的,感觉太繁琐,为了建立一个空的控制台程序,要建立那么大一个文件,费得劲比较大,所以想着利用Linux中的gcc来编译,只要写一个.cpp的文件就可以了。可是对这个不是很了解,抄了一个文件进行编译,却出现好多的错误,可能是需要进行这样那样的设置的吧。特此立帖,希望达人能给我一些建议,如果可以能提供更好的编译器,那是更加的好了。谢谢先了
我用的sample
sample
#include <iostream>
#include <vector>
using namespace std;
main()
{
vector< vector<int> > vI2Matrix; // Declare two dimensional array
vector<int> A, B;
vector< vector<int> >::iterator iter_ii;
vector<int>::iterator iter_jj;
A.push_back(10);
A.push_back(20);
A.push_back(30);
B.push_back(100);
B.push_back(200);
B.push_back(300);
vI2Matrix.push_back(A);
vI2Matrix.push_back(B);
cout << endl << "Using Iterator:" << endl;
for(iter_ii=vI2Matrix.begin(); iter_ii!=vI2Matrix.end(); iter_ii++)
{
for(iter_jj=(*iter_ii).begin(); iter_jj!=(*iter_ii).end(); iter_jj++)
{
cout << *iter_jj << endl;
}
}
}
输出的错误:
[root@localhost Cpp]# gcc SampleVector.cpp
/tmp/ccJVmST1.o(.text+0x1ee): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
/tmp/ccJVmST1.o(.text+0x1fe): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
/tmp/ccJVmST1.o(.text+0x203): In function `main':
: undefined reference to `std::cout'
/tmp/ccJVmST1.o(.text+0x208): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccJVmST1.o(.text+0x211): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
……
诸如此类的错误,我该怎么办呢?