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>包括标准输入输出库函数。它提供cincout方法分别用于从输入读取和写入到输出。

#include <conio.h>包括控制台输入输出库函数。getch() 函数在 conio.h 文件中定义。

void main() main() 函数是每个C++ 语言程序的入口点。void 关键字指定它不返回任何值。

cout << "欢迎来到 C++ 编程。" 用于打印数据“欢迎来到 C++ 编程。”。在控制台上。

getch() getch() 函数要求输入单个字符直到你按下任何键,它都会挡住屏幕。

Cpp 程序 1

VS2010打印结果

如何编译和运行 C++ 程序

编译和运行 C++ 程序有两种方法,通过菜单和通过快捷方式。

按菜单

现在点击编译菜单然后编译子菜单来编译c++程序。

然后点击运行菜单然后运行子菜单运行c++程序。

通过快捷方式

或者,直接按ctrl+f9键编译运行程序。

您将在用户屏幕上看到以下输出。

Cpp 程序 2

您可以通过按alt+f5随时查看用户屏幕。

现在按 Esc返回到 turbo c++ 控制台。


上一主题 C++ 安装 下一主题 C++ 基本输入/输出
  • 使用社交账号登录,本站支持
全部评论(0)