你所不知道的Hello World[C++實現]


要說OIer界內最簡單的程序,那恐怕非Hello World莫屬了, 那么這篇文章就介紹如何寫Hello World(被打)。

  • 最簡單的一種實現:

#include <iostream>
using namespace std;
int main(){
    cout << "Hello World" << endl;\
    cin.get();
    return 0;
}

  • 當用戶按下按鍵的時候顯示Hello World,松開就消失。

#include <iostream>
#include <cstdio>
#include <conio.h>
using namespace std;

int main(){
    while(1){
        if(_kbhit()){
            cout << "Hello World";
            system("cls");
            _getch();
        }
    }
    return 0;
}

  • 設置文字顏色及大小(需要安裝圖形庫)

#include <graphics.h>
#include <conio.h>

int main(){
    initgraph(600,480);
    settextcolor(RGB(2,134,219));
    settextstyle(60, 0, _T("微軟雅黑"));
    outtextxy(180,200,_T("Hello World"));
    _getch();
    closegraph();
    return 0;
}

運行截圖:


  • 讓電腦說:Hello World
#include <windows.h>
#include <mmsystem.h>
#include <conio.h>

int main(){
    mciSendString("open say.mp3 alias music",NULL,0,NULL);
    mciSendString("play music repeat",NULL,0,NULL);
    _getch();
    return 0;
}

運行上面的代碼需要用錄音器錄制一段Hello World的音頻,然后把它放在程序的目錄內,命名為say.mp3(注意不要有二級后綴)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM