我制作了这样的函数来以字符串形式获取所需的时间信息。
string gettimeinfo()
{
tm * timeinfo;
time_t rawtime;
char timebuff[120] = {0};
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(timebuff, 120, "%d.%m.%Y. %H:%M:%S %x %W %I:%M %p %a %b %A %B %Z\n", timeinfo);
return string(timebuff);
}
这编译没有错误并按预期工作。
但是当调试 code:blocks/GCC 程序在 return 语句处停止并出现调试警告:
In std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) () ()
会发生什么以及如何摆脱这种情况?
编辑:整个错误是:
In std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned int, std::allocator<char> const&) () ()
#1 0x004013fe in gettimeinfo () at C:\programi\[connectcpp\general.cpp:36
C:\programi\[connectcpp\general.cpp:36:785:beg:0x4013fe
At C:\programi\[connectcpp\general.cpp:36
In char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) () ()
In std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) () ()
In operator new(unsigned int) () ()