关于G++编译器的C++stl错误
代码:#include<iostream>#include<vector>usingnamespacestd;template<classT>voidlistinfo(v...
代码:
#include <iostream>
#include <vector>
using namespace std;
template<class T>
void listinfo(vector<T> &v)
{
cout << "Container capacity: " << v.capacity() << endl;
cout << "Container size: " << v.size() << endl;
}
int main()
{
vector<double> data;
listinfo(data);
cout << endl << "After calling reserve(100)" << endl;
data.reserve(100);
listinfo (data);
vector<int> numbers(10,-1);
cout << endl<< "the initial values are: " << endl;
for(vector<int> ::size.type i = 0; i < numbers.size(); i ++)
{
cout << "" << numbers[i];
}
auto oldC = numbers.capacity();
auto newC = oldC;
cout << endl << endl;
listinfo (numbers);
for(int i = 0; i < 1000; i ++)
{
numbers.push_back(2*i);
newC = numbers.capacity();
if(oldC < newC)
{
oldC = newC;
listinfo (numbers);
}
}
return 0;
}
编译出错; 展开
#include <iostream>
#include <vector>
using namespace std;
template<class T>
void listinfo(vector<T> &v)
{
cout << "Container capacity: " << v.capacity() << endl;
cout << "Container size: " << v.size() << endl;
}
int main()
{
vector<double> data;
listinfo(data);
cout << endl << "After calling reserve(100)" << endl;
data.reserve(100);
listinfo (data);
vector<int> numbers(10,-1);
cout << endl<< "the initial values are: " << endl;
for(vector<int> ::size.type i = 0; i < numbers.size(); i ++)
{
cout << "" << numbers[i];
}
auto oldC = numbers.capacity();
auto newC = oldC;
cout << endl << endl;
listinfo (numbers);
for(int i = 0; i < 1000; i ++)
{
numbers.push_back(2*i);
newC = numbers.capacity();
if(oldC < newC)
{
oldC = newC;
listinfo (numbers);
}
}
return 0;
}
编译出错; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询