hello c++ demo c++基本语法

来源:互联网 发布:程序员考试难吗 编辑:程序博客网 时间:2024/06/11 14:06

hello c++ demo c++基本语法

#include <iostream>/* run this program using the console pauser or add your own getch, system("pause") or input loop *//**是预处理指令,以#开头的指令将交给预处理器处理。<>指从标准位置查找头文件stdio.h(因为下面要用到printf函数,所以要先拷贝该文件,它包含了printf函数)**/#include<stdio.h>#include<stdlib.h>using namespace std;int main(void) {int x=100;cout<<x<<endl<<x;    printf("hello c++");return 0;}

#include <iostream>/* run this program using the console pauser or add your own getch, system("pause") or input loop *//**是预处理指令,以#开头的指令将交给预处理器处理。<>指从标准位置查找头文件stdio.h(因为下面要用到printf函数,所以要先拷贝该文件,它包含了printf函数)**/#include<stdio.h>#include<stdlib.h>using namespace std;int main(void) {   cout<<"请输入一个整数"<<endl;    int x=0;   cin>> x;   cout<<oct<<x<<endl; //八进制    cout<<dec<<x<<endl; //十进制    cout<<hex<<x<<endl; //十六主进制   cout<<"请输入一个布尔值(0,1):"<<endl;   bool y=false;   cin>>y;   cout<<boolalpha<<y<<endl;   system("pause"); return 0;}


#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;//namespace 的应用  ::namespace A{int x=1;void fun(){cout<<"A"<<endl;}}namespace B{int bx=2;void fun(){cout<<"B"<<endl;}}using namespace B;int main(void){cout<<A::x<<endl; //::引用 namespaceB::fun(); //::引用  namespacecout<<bx<<endl; //using 引用  namespacesystem("pause");return 0;}

1 0
原创粉丝点击