c++ - 编写一个主程序为空但打印“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
.
- 那么我的所有情况都是明确定义的还是有灾难性的?谢谢你。
解决方案
推荐阅读
- java - 无论我做什么,我都无法让 Java 识别文本文件的文件路径
- python - 删除最后一个字符在连接后循环的第一次运行中不起作用
- node.js - Adding custom definitions file for passport-twitchtv
- c# - polling server after POST 201 CREATED c#
- scala - Future and Option in for comprehension in slick
- python - 重新分配在 __init__ 函数中声明的类实例属性的正确方法是什么?
- javascript - 如何在 Typescript 中更新数组列表的对象?
- assembly - 使用 ASCII 值作为名称的 MIPS 汇编语言代码
- ruby-on-rails - Cryptic Error when using firebase in rails
- python - pip 安装失败:cl.exe 失败,退出状态为 2