小编are*_*euz的帖子

为什么'直到'存在?

是否有任何理由将命令until实现到bash/shell中(我还不确定哪个)?对于while声明的否定,你有什么不能做的吗?它比使用NOTCPU功能更快吗? - 不太可能......

linux bash shell

20
推荐指数
3
解决办法
3489
查看次数

一次处理所有传递的重载

我厌倦了在现场调试代码并包含<iostream>在每个文件中.所以我想让自己成为一个通用的,自包含的,轻量级的调试类,我将只包含在标题中,然后忘记.

我想用一些东西

#include "debug.hpp"
debug DBG;
DBG << "foo and" << " bar";
//Or even better, just include it and do debug() << "foo and" << " bar";
Run Code Online (Sandbox Code Playgroud)

所以,我写了这个:

#include <iostream>
#include <string>
#include <chrono>
#include <ctime>

class Debug
{
public:    
  Debug &operator<<(std::string arg_0)
  {
    auto tempTime = std::chrono::system_clock::to_time_t(
      std::chrono::system_clock::now() );
    auto timeString(ctime(&tempTime));
    timeString = timeString.substr(timeString.find(':') - 2, 8);

    std::cout << timeString << " >> " << arg_0 << '\n';
    return *this;
  }
};
Run Code Online (Sandbox Code Playgroud)

但是,当然,这不起作用,因为正如我所知,每个重载操作符都会导致此函数(它仍被称为函数?)单独触发.创建:

hour:minute:second >> foo …
Run Code Online (Sandbox Code Playgroud)

c++ cross-platform operator-overloading c++11

0
推荐指数
1
解决办法
55
查看次数

标签 统计

bash ×1

c++ ×1

c++11 ×1

cross-platform ×1

linux ×1

operator-overloading ×1

shell ×1