我遇到了 STL C++ 的 shrink_to_fit() 函数的问题。问题是我使用它时,编译器在使用 MinGW 编译器的 Eclipse Luna(32 位)上给出错误“无法解析方法‘shrink_to_fit’,但同一程序在 Dev C++ 中运行良好。
编译器不建议在使用点 (.) 后使用 shrink_to_fit():
原代码:
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
vector<int> v(128);
cout << "Initial capacity = " << v.capacity() << endl;
v.resize(25);
cout << "Capacity after resize = " << v.capacity() << endl;
v.shrink_to_fit();
cout << "Capacity after shrink_to_fit = " << v.capacity() << endl;
return 0;
}
请告诉我这是我的错还是 IDE 的错。
附言我正在使用 C++14。
最佳答案
在
面向 C/C++ 开发人员的 Eclipse IDE, 版本:2019-09 R (4.13.0) 内部版本号:20190917-1200 操作系统:Windows 10,v.10.0,x86_64/win32 Java版本:13.0.1
以及在 Linux 上(使用 -std=c++11 标志和 GCC 7.4.0 编译器)。这可能是您的 IDE、编译器(带有正确标志)或 STL 实现的问题。在我看来,不可能有第四个原因。
关于c++ - 无法解析方法 'shrink_to_fit',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58634410/