代码之家  ›  专栏  ›  技术社区  ›  bbaja42

写“你好世界”的奇怪方式[复制]

c++
  •  1
  • bbaja42  · 技术社区  · 17 年前

    可能重复:
    Changing c++ output without changing the main() function
    How to assign a method's output to a textbox value without code behind

    如何在不修改主函数的情况下编写hello world? 谢谢

    int main(){return 0;}
    
    4 回复  |  直到 12 年前
        1
  •  12
  •   Nathaniel Flath    17 年前
    #include<iostream>
    
    int hello() {
        cout<<"Hello World"<<endl;
    }
    
    static int foo = hello();
    
    int main(){return 0;}
    
        2
  •  11
  •   JaredPar    17 年前

    只需将此代码添加到某个.cpp文件中。

    class Hack {
      Hack() { cout << "Hello World"; }
    } hackInstance;
    
        3
  •  4
  •   Dave Bauman    17 年前

    使用预处理器为返回定义扩展以打印hello world,然后返回。

        4
  •  1
  •   Stefan Kendall    17 年前

    我假设有一个创造性的使用定义预处理器语句,可以使这个工作。