我正在尝试使用string成员函数back()和pop_back(),但我认为我的编译器没有将它们识别为成员。但是,当我使用-std=c++0x选项时,编译器停止只抱怨back(),但仍然抱怨pop_back()。下面是代码和编译器错误:
Test.cpp:
#include <iostream> // std::cout
#include <string> // back(), pop_back()
int main()
{
std::string str ("Optimist!");
std::cout << str.back() << "\n";
str.pop_back();
std::cout << str << "\n";
}g++ Test.cpp:
Test.cpp: In function ‘int main()’:
Test.cpp:8:20: error: ‘std::string’ has no member named ‘back’
Test.cpp:9:7: error: ‘std::string’ has no member named ‘pop_back’g++ -std=c++0x Test.cpp:
Test.cpp: In function ‘int main()’:
Test.cpp:9:7: error: ‘std::string’ has no member named ‘pop_back’k’如何在g++中使用这些函数?
编辑:使用g++ 4.6.3
发布于 2014-01-02 20:42:56
std::basic_string::pop_back()和std::basic_string::back()都是添加到C++11中。,如果没有显式地使用C++11标准和-std=c++11,则根本无法使用这些函数。
GCC目前的版本是4.8.2。一些早期版本可能没有实现这些功能中的一个或两个。如果需要的话,应该升级到4.8.2。
https://stackoverflow.com/questions/20891441
复制相似问题