C++ 程序
在开始 C++ 语言的 abcd 之前,您需要学习如何编写、编译和运行第一个 C++ 程序。
要编写第一个 C++ 程序,请打开 C++ 控制台并编写以下代码:
例子 (Example)
#include <iostream.h>
#include<conio.h>
void main() {
clrscr();
cout << "欢迎来到 C++ 编程。";
getch();
}
VS2010例子 (Example)
#include <iostream>
using namespace std;
int main()
cout << "Hello, world!" << endl;
getchar();
system("pause");
return 0;
}
其它例子 (Example)
#include <iostream>
using namespace std;
int main()
cout << "Hello, world!" << endl;
return 0;
}
#include<iostream.h>
包括
标准输入输出
库函数。
它提供
cin
和
cout
方法分别用于从输入读取和写入到输出。
#include <conio.h>
包括
控制台输入输出
库函数。
getch() 函数在 conio.h 文件中定义。
void main()
main() 函数是每个
C++ 语言程序
的入口点。
void 关键字指定它不返回任何值。
cout << "欢迎来到 C++ 编程。"
用于
打印数据“
欢迎来到 C++ 编程。
”。
在控制台上。
getch()
getch() 函数
要求输入单个字符
。
直到你按下任何键,它都会挡住屏幕。
VS2010打印结果
如何编译和运行 C++ 程序
编译和运行 C++ 程序有两种方法,通过菜单和通过快捷方式。
按菜单
现在
点击编译菜单然后编译子菜单
来编译c++程序。
然后
点击运行菜单然后运行子菜单
运行c++程序。
通过快捷方式
或者,直接按ctrl+f9
键编译运行程序。
您将在用户屏幕上看到以下输出。
您可以通过按alt+f5
键
随时查看用户屏幕。
现在
按 Esc
返回到 turbo c++ 控制台。