Hello, World!

来源:互联网 发布:诊所管理系统源码 编辑:程序博客网 时间:2024/06/07 16:59

C++经典版

#include <stdio.h>#include <iostream>int main(){    printf("Hello world!");                   // 教科书的写法    puts("Hello world!");                     // 我最喜欢的    puts("Hello" " " "world!");               // 拼接字符串    std::cout << "Hello world!" << std::endl; // C++风格的教科书写法    return 0;}

宏版

#include <stdio.h>#define Say(sth) puts(#sth)int main(){    return Say(Hello world!);}

字符串版

#include <stdio.h>int main(){    return puts(&"Do not say: Hello world!"[12]);}

退出程序版

#include <stdio.h>#include <stdlib.h>void say(){    printf("world!");}void sth(){    printf("Hello ");}int main(){    return atexit(say), atexit(sth);}

文件名版

// Hello world!#include <iostream>#include <fstream>#include <string>int main(){    std::ifstream ifs(__FILE__);    std::string say, some, word;    ifs >> say >> some >> word;    std::cout << some << " " << word;    return 0;}

全局变量版

#include <iostream>class say{public:    say()    {        std::cout << "Hell";    }    ~say()    {        std::cout << "world!";    }}hello;int main(){    std::cout << "o ";    return 0;} 


0 0
原创粉丝点击