Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
语言环境格式时间输出的实现 我试图在程序中实现.< /P>中C++中打印区域时间的代码。_C++_Datetime_Locale_Overloading - Fatal编程技术网

语言环境格式时间输出的实现 我试图在程序中实现.< /P>中C++中打印区域时间的代码。

语言环境格式时间输出的实现 我试图在程序中实现.< /P>中C++中打印区域时间的代码。,c++,datetime,locale,overloading,C++,Datetime,Locale,Overloading,我做了一些修改,使代码适应我的标题,但它仍然给我一个错误“方法‘put’无法解决”。我是新手,所以我找不到答案。我在月食上。我已将编辑器的可伸缩性编号设置为50000。此外,该文件还有一个介于包含和代码之间的类 代码如下: #ifndef LISTA_H_ #define LISTA_H_ #include "nodel.h" #include "hntable.h" #include <iostream> #include <string> #include <

我做了一些修改,使代码适应我的标题,但它仍然给我一个错误“方法‘put’无法解决”。我是新手,所以我找不到答案。我在月食上。我已将编辑器的可伸缩性编号设置为50000。此外,该文件还有一个介于包含和代码之间的类

代码如下:

#ifndef LISTA_H_
#define LISTA_H_

#include "nodel.h"
#include "hntable.h"

#include <iostream>
#include <string>
#include <iterator>
#include <time.h>

using namespace std;

class timefmt
{
public:
    timefmt(std::string fmt)
        : format(fmt) { }

    friend ostream& operator <<(ostream &, timefmt const &);

private:
    string format;
};


std::ostream& operator <<(std::ostream& os, timefmt const& mt)
{
    std::ostream::sentry s(os);

    if (s)
    {
        time_t t = time(0);
        tm const* tm = localtime(&t);
        ostreambuf_iterator<char> out(os);

        use_facet<time_put<char>>(os.getloc())
            .put(out, os, os.fill(),
                 tm, &mt.format[0], &mt.format[0] + mt.format.size());
    }

    os.width(0);

    return os;
}

#endif /* LISTA_H_ */
\ifndef LISTA\u H_
#定义列表a_H_
#包括“nodel.h”
#包括“hntable.h”
#包括
#包括
#包括
#包括
使用名称空间std;
课堂时间
{
公众:
timefmt(标准::字符串fmt)
:格式(fmt){}

friend ostream&operator只需添加
#include
,您的代码中有许多错误……您是否发布了所有代码?我没有看到“tm”类型定义/声明。@Miguel
tm
is@IgorTandetnik我甚至不知道它的存在,我还以为它是一个用户定义的类型,但他忘了声明。谢谢。现在它与put没有问题,但是'operatorDon'的多个定义没有在头文件中定义函数。在头文件中声明函数,在一个源文件中定义函数。