GVKun编程网logo

"std::endl" 与 " "

13

想了解"std::endl"与""的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于/usr/include/c++/7/cstdlib:75:15:fatalerror:stdlib.

想了解"std::endl" 与 " "的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory、Android Handler.postDelayed()方法、android – Handler.postDelayed(Runnable)vs CountdownTimer、android – handler.postDelayed在IntentService的onHandleIntent方法中不起作用的新知识。

本文目录一览:

"std::endl" 与 " "

许多 C++ 书籍都包含这样的示例代码......

std::cout << "Test line" << std::endl;

…所以我也一直这样做。但是我已经看到很多这样的工作开发人员的代码:

std::cout << "Test line\n";

是否有技术上的理由比另一个更喜欢一个,或者这只是编码风格的问题?

答案1

小编典典

假设文件以文本模式打开,则不同的行尾字符无关紧要,除非您要求二进制文件,否则您会得到这样的结果。编译后的程序将为编译的系统写出正确的东西。

唯一的区别是std::endl刷新输出缓冲区,而''\n''不是。如果您不想频繁刷新缓冲区,请使用''\n''.
如果你这样做(例如,如果你想获得所有输出,并且程序不稳定),请使用std::endl.

/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

这里写自定义目录标题

  • Ubuntu 18.04编译opencv-3.2.0时出现如下错误:
  • 原因分析:
  • 解决方法:

Ubuntu 18.04编译opencv-3.2.0时出现如下错误:

[ 20%] Generating precomp.hpp.gch/opencv_viz_Release.gch
In file included from /usr/include/c++/7/ext/string_conversions.h:41:0,
                 from /usr/include/c++/7/bits/basic_string.h:6361,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/stdexcept:39,
                 from /usr/include/c++/7/array:39,
                 from /usr/include/c++/7/tuple:39,
                 from /usr/include/c++/7/bits/stl_map.h:63,
                 from /usr/include/c++/7/map:61,
                 from /home/hri/MyInstallSoftware/opencv-3.2.0/build/modules/viz/precomp.hpp:49:
/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
               ^~~~~~~~~~
compilation terminated.
modules/viz/CMakeFiles/pch_Generate_opencv_viz.dir/build.make:62: recipe for target 'modules/viz/precomp.hpp.gch/opencv_viz_Release.gch' failed
make[2]: *** [modules/viz/precomp.hpp.gch/opencv_viz_Release.gch] Error 1
CMakeFiles/Makefile2:3122: recipe for target 'modules/viz/CMakeFiles/pch_Generate_opencv_viz.dir/all' failed
make[1]: *** [modules/viz/CMakeFiles/pch_Generate_opencv_viz.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

原因分析:

这是由于gcc7已经吧stdlib.h纳入了libstdc++以进行更好的优化,C Library的头文件stdlib.h使用 Include_next,而include_next对gcc系统头文件路径很敏感。

推荐的修复方法是不要把include路径作为系统目录,而是使用标准方式包含include 目录

解决方法:

在编译opecv-3.2.0时,加入如下选项:

-DENABLE_PRECOMPILED_HEADERS=OFF
  • 1

Android Handler.postDelayed()方法

Android Handler.postDelayed()方法

Android Handler.postDelayed()方法

   1.认识Handler.postDelayed()方法

      为一种实现多线程方法,通过创建一个Handler对象和一个Runnable对象;使用postDelayed()方法

    使之从新调用Runnable对象

 

   ·2,源码

      2.1 创建一个Handler对象:

        Handler handler=new Handler();、

      2.2 然后创建一个Runnable对象;

      Runnable runnable=new Runnable(){
       @Override
        public void run() {
       // TODO Auto-generated method stub
       //想要做的事情
       }
      };         

      2.3 使用postDelayed()方法

        //两秒后调用此Runnable对象

        handler.postDelayed(runnable, 2000);

      2.4 关闭此定时器

        handler.removeCallbacks(runnable);

 

android – Handler.postDelayed(Runnable)vs CountdownTimer

android – Handler.postDelayed(Runnable)vs CountdownTimer

有时我们需要在代码运行之前延迟它.

这可以通过Handler.postDelayed(Runnable)或CountdownTimer来实现.

Which one is better in terms of performance?

请参阅下面的示例代码

处理器

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                 //DO SOMETHING
            }
        },1000);

倒计时器

new CountDownTimer(1000,1000) {
            public void onFinish() {
                 //DO SOMETHING
            }
            public void onTick(long millisUntilFinished) {}
        }.start();

解决方法

处理程序应该为您提供更好的性能,因为CountDownTimer包含一个Handler,你可以看到 here.

android – handler.postDelayed在IntentService的onHandleIntent方法中不起作用

android – handler.postDelayed在IntentService的onHandleIntent方法中不起作用

final Handler handler = new Handler();
LOG.d("delay");
handler.postDelayed(new Runnable() {
    @Override public void run() {
        LOG.d("notify!");
        //calling some methods here
    }
}, 2000);

“延迟”确实显示在日志中,但根本不显示.并且在run()中调用的方法也根本不被调用.任何人都可以帮助解释为什么会发生这种情况,我做错了吗?

具有此代码的类扩展了IntentService,这会是一个问题吗?

============================

更新:
我将此代码放在扩展IntentService的类中.我发现它唯一有用的地方是构造函数.但我需要把它放在onHandleIntent方法中.所以我检查了onHandleIntent的文档,它说:

This method is invoked on the worker thread with a request to process.Only one Intent is processed at a time, but the processing happens on a worker thread that runs independently from other application logic. So, if this code takes a long time, it will hold up other requests to the same IntentService, but it will not hold up anything else. When all requests have been handled, the IntentService stops itself, so you should not call stopSelf.

所以基于我得到的结果,我觉得我不能在“工作线程”中使用postDelayed.但是,任何人都可以解释这一点,比如为什么这不适用于工作线程?提前致谢.

解决方法:

您正在使用主线程的looper.您必须创建一个新的循环器,然后将其提供给您的处理程序.

HandlerThread handlerThread = new HandlerThread("background-thread");
handlerThread.start();
final Handler handler = new Handler(handlerThread.getLooper());
handler.postDelayed(new Runnable() {
    @Override public void run() {
        LOG.d("notify!");
        // call some methods here

        // make sure to finish the thread to avoid leaking memory
        handlerThread.quitSafely();
    }
}, 2000);

或者您可以使用Thread.sleep(long millis).

try {
    Thread.sleep(2000);
    // call some methods here

} catch (InterruptedException e) {
    e.printstacktrace();
}

如果要停止休眠线程,请使用yourThread.interrupt();

我们今天的关于"std::endl" 与 " "的分享已经告一段落,感谢您的关注,如果您想了解更多关于/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory、Android Handler.postDelayed()方法、android – Handler.postDelayed(Runnable)vs CountdownTimer、android – handler.postDelayed在IntentService的onHandleIntent方法中不起作用的相关信息,请在本站查询。

本文标签:

上一篇ConcurrentHashMap 和 Collections.synchronizedMap(Map) 有什么区别?(concurrenthashmap的区别)

下一篇从 Android 应用程序访问 Internet 需要什么权限?(安卓程序访问网络的方法)