首页 > 解决方案 > 编写一个主程序为空但打印“hello there!”的程序 屏幕上

问题描述

您好,有人要求我编写一个主函数体为空的 C++ 程序,但该程序应打印:"hi there!".

所以我这样做了:

#include <iostream>


struct Foo
{
    Foo(){std::cout << "hi there!\n";}
}fobj;

int bar()
{
    std::cout << "hi there!\n";
    return 0; // arbitrary value
}

int x{bar()};
double pi = (std::cout << "hi there!\n", 3.14);



int main()
{

}

输出:

hi there!
hi there!
hi there!

从我的代码块看起来它工作正常,但在我的手机上使用“编码 C++”它说:process terminated. signal 11.

标签: c++

解决方案


推荐阅读