首页 > 编程语言 > 详细

你所不知道的Hello World[C++实现]

时间:2020-02-17 19:42:55      阅读:66      评论:0      收藏:0      [点我收藏+]

要说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");
    _getch();
    return 0;
}



运行上面的代码需要用录音器录制一段Hello World的音频,然后把它放在程序的目录内,命名为say.mp3(注意不要有二级后缀)

你所不知道的Hello World[C++实现]

原文:https://www.cnblogs.com/Return-blog/p/12323000.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!