【C/C++】C++与C的日常回忆总结

C++与C的日常回忆总结

c的写法:scanf printf

  1. #include <stdio.h>
  2. int main(){ 
  3.  printf("输出")//输出
  4.  scanf("%d",&a);//输入   %d整型  %c字符 %s字符串  
  5.  return 0;
  6. }


c++的写法: cout<<   cin>>
  1. #include <iosstream>
  2. using namespace std;
  3. int main(){ 
  4.  cout << "Hello, World! I am " << 18 << " Today!" << endl;//输出
  5.  cin >> number;//输入
  6.  return 0;
  7. }

  

用面向对象的思路对比C/C++写法的
C的写法:


  1. typedef struct point3d{
  2.   float x; float y;float z;
  3. }Point3d;
  4. void Point3d_print(const Point3d* 3d);
  5. Point3d a;
  6. a.x = 1 ; a.y = 2 ; a.z=3;
  7. Point3d_print(&a);

    
    C++的写法

  1. class Point3d {
  2. public:
  3.    Point3d(float x,float y,float z);
  4.    print();
  5. private:
  6.   float x; float y;float z;
  7. };
  8.   
  9.  Point3d a(1,2,3);
  10.  a.print();

  


    c的定义宏  调试宏

  1. #include <stdio.h>

    int main(){

      printf("%s,%s,%dxxx\n",__FUNCTION__,__FILE__,__LINE__);

       return 0;

    }

     运行:
    main,001.c,3xxx

__FUNCTION__,__FILE__,__LINE__

函数名     文件名      行号



     c一般的基础   输出 10.00000

  1. #include <stdio.h>
    int main(){
    printf("%f",10/3.0*3);
    return 0;

     
     c一般的基础   没有输出 被我骗了?

  1. #include <stdio.h>
    int main(){
    int a= 7;
    int b = 6;
    if ( a == 6 )
        if ( b == 7 ) 
            printf("A");
    else
        printf("B"); 
    return 0;




     C++的写法

  1. class Point3d {
  2. public:
  3.    Point3d(float x,float y,float z);
  4.    print();
  5. private:
  6.   float x; float y;float z;
  7. };
  8.   
  9.  Point3d a(1,2,3);
  10.  a.print();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值