标签:scanf hello cond c中 stream 输入 面向对象 namespace printf
c++入门程序
c中的输入和输出,一般使用标准库中printf,scanf去进行读写。
#if 0 #include<stdio.h> int main() { //输出 printf("hello world...\n"); //输入 int a = 0; printf("请输入一个整数:"); scanf("%d", &a); return 0; } #endif
#if condition...#endif c/c++中的预编译指令,只有当条件满足时才去编译。
作为对比:
c++中简化了对输入输出的书写,通过引入标准命名空间std的方式使用cin,cout进行标准的输入输出。
#include<iostream> using namespace std; //std{ // cout... //iostream有一个标准的命名空间std,定义了cin,cout等关键字 //} int main(void) { //输出 cout << "helloworld" << endl; //输入 int a = 0; cout << "请输入一个整数:"; cin >> a; cout << "a="<< a << endl; return 0; }
通过书写可以看出c++完全继承c的特性,但又多了面向对象的特征。
标签:scanf hello cond c中 stream 输入 面向对象 namespace printf
原文地址:https://www.cnblogs.com/knight11/p/9762658.html