我正在尝试编写可以在POJ上编译的代码。POJ不使用C++11,因此我不能使用基本的STL函数,如std::to_string
、std::begin
或std::end
。我四处寻找并找到了另一个StackOverflow问题,询问std::to_string
。为了让std::to_string
代码能够通过裸的g++ myfile.cpp
命令进行编译,有用户建议使用这个补丁,效果很好:
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
我想对
std::begin
、std::end
和std::stoi
做同样的事情,但我不确定如何做。我对STL并不熟悉。我只想让我的C++11代码能够在MS-VC++6.0或G++上编译,不需要任何标志等。我该怎么做?
namespace std
中,但你可以绕过这个问题。 - Neil Kirkc.begin()
的版本,但另一个版本专门针对数组。 - Neil Kirk