我面临一个问题,与shrink_to_fit()函数的STL C++。问题是我使用它时,编译器在Eclipse露娜(32位)的MinGW编译器上给出了错误的“方法‘’MinGW‘无法解决’,但是在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。
发布于 2019-10-31 13:20:10
它对我很好(有-std=c++11标志,和https://nuwen.net/mingw.html#install的MinGW发行版)
供C/C++开发人员使用的Eclipse,版本: 2019-09 R (4.13.0)构建id: 20190917-1200 OS: Windows 10,v.10.0,x86_64 / win32 Java版本: 13.0.1
以及Linux (带有-std=c++11标志和GCC 7.4.0编译器)。这可能是IDE、编译器(带有正确标志)或STL实现的问题。在我看来,不可能有第四个原因。
发布于 2019-10-30 23:12:54
对我来说很好。试着用手工编译,看看它是否是关于ide的:
g++ foo.cpp -o foo
./foohttps://stackoverflow.com/questions/58634410
复制相似问题