第一个C++程序

后台语言真恶心,总要面对那个黑黢黢的控制台……

#include 
using namespace std;

void Hello(string const name){
    cout << "Hello! " << name << "!" << endl;
}

int main(){
     Hello("C++");
     while(1);
}

增添交互功能:

#include 
using namespace std;

void Hello(string const name){
    cout << "Hello! " << name << "!" << endl;
}

int main(){
    string name;
    cout << "请输入你的名字";
    getline(cin,name);//getline为标准库的函数,直接可用
    Hello(name);
    while(1);
}
#include 
using namespace std;
void Hello(string const name){
    cout << "Hello! " << name << "!" << endl;
}

另一种不会自动关闭窗口的方法:

#include 
int main(){
    using namespace std;
    cout << "请敲两次键盘,窗口就会消失。"<< endl;
    cin.get();
    cin.get();
    return 0;
}
原文地址:https://www.cnblogs.com/rubylouvre/p/1913226.html