后台语言真恶心,总要面对那个黑黢黢的控制台……
#includeusing namespace std; void Hello(string const name){ cout << "Hello! " << name << "!" << endl; } int main(){ Hello("C++"); while(1); }
增添交互功能:
#includeusing namespace std; void Hello(string const name){ cout << "Hello! " << name << "!" << endl; } int main(){ string name; cout << "请输入你的名字"; getline(cin,name);//getline为标准库的函数,直接可用 Hello(name); while(1); }
#includeusing namespace std; void Hello(string const name){ cout << "Hello! " << name << "!" << endl; }
另一种不会自动关闭窗口的方法:
#includeint main(){ using namespace std; cout << "请敲两次键盘,窗口就会消失。"<< endl; cin.get(); cin.get(); return 0; }