呵呵,各位老大,HELLO THE WORLD有101种解法吗??!!
我从精品上看到的,有一个人列出了5种解法。。。。我只有三种,呵呵,晕
下面开始是精品转贴过来的内容:
我计划征集用C/C++实现"Hello World"的101种解法,比如以下的方法:
(我在VC.net下用命令行"cl /GX filename" 编译通过),请各位各显神通拿出压箱底的本领吧!
另外:我的贴子" 程序员必读――搞清楚概念先!!!【原创】"遭到漫骂甚至人身攻击,太令我心寒了,难道现在的论坛风气真的如此?唉…
//ex1.cpp C最经典的
#include <stdio.h>
int main()
{
printf(“Hello World!\n”);
return 0;
}
////////////////////////////////////////////////
//ex2.cpp C++最经典的
#include
using namespace std;
int main()
{
cout << “Hello World.” << endl;
return 0;
}
///////////////////////////////////////////////
//ex3.cpp C++构造函数初级用法
#include
#include
using namespace std;
class HelloWorld
{
public:
HelloWorld(string s = “Hello World!\n”)
{
cout << s;
}
};
int main()
{
HelloWorld Greeting;
return 0;
}
///////////////////////////////////////////////
//ex4.cpp C++重载运算符
#include
#include
using namespace std;
void operator → (const string& s1, const string& s2)
{
cout << s1;
cout << s2;
}
int main()
{
string str1("Hello ");
string str2(“World!\n”);
str1 → str2; //我迷死你(“迷惑死你”简称),
return 0;
}
////////////////////////////////////////////////////////
//ex5.cpp 有点杀鸡用牛刀的感觉
//使用泛型算法
#include
#include
#include
#include
#include
using namespace std;
int main()
{
string s = {“Hello”, “World”, “!\n”};
vectortext(s, s + 3);
ostream_iteratoros(cout, " ");
copy(text.begin(), text.end(), os);
return 0;
}
///////////////////////////////////////////////////////
//ex6.cpp 指针大法,我用指针顶顶顶…
#include
#include
#include
using namespace std;
int main()
{
ostream_iteratorout(cout);
*out = "Hello, ";
out++;
*out = “World!\n”;
return 0;
}