在我的代码中的一个函数中,我发现了一个 bug。它被写成了 std:string
:
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
//strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
strftime(buf, sizeof(buf), "%Y%m%d%X", &tstruct);
std:string str = buf;
str.erase(std::remove(str.begin(), str.end(), ':'), str.end());
return str;
}
代码编译没有错误。为什么它能够编译通过?那么std:string
是什么意思呢?
using namespace std;
本不该存在于那里。修复了Bug #1后编译失败了,报告了Bug #2std::string
的问题。 - JSF