zoukankan      html  css  js  c++  java
  • c++基本数据类型

    着重介绍字符串类型

    int 占4字节

    定义:int a = 34234;

    int main(int argc, char* argv[]){
    int a[10] = {1,2,3,4}; //可以看A是一个指针,指向的是首元素地址
    int* p = a; //a=首元素地址,*a=1,此句等效于 int* p=&a[0]
    cout<<p<<endl; //output:1的地址
    cout<<*p<<endl; //output:1
    cout<<a+2<<endl; //output:3的地址
    cout<<*(a+2)<<endl; //output:3
    cout<<&a[0]<<endl;
    }

    char 字符,占1字节

    定义:char a = 'x';  //必须是单引号

    char a[] 多个字符(也就是数组)

    定义:char a[] = "asdfasdfsadf";

    a存放的是数组首个元素的地址,和&a[0]等效,所以用int* p = a时,p存放的其实是a[0]的地址,

     

    string 字符串

    定义:string a = "asdfasfd";    //必须使用头部#include<string>和using namespace std;

    void main ()
    {
        string name="abc";
        cout<<name[0]<<endl;        //output : a
        string name[2]={"abc","edf"};
        cout<<name[0]<<endl;        //output : abc
    }

    enum枚举

    定义:

    enum color{red=2,yellow,blue=8,green}; 
    cout<< red <<endl << yellow<< endl<< blue<< endl<<green<<endl;   //output: 2,3,8,9
    namespace NS{
      enum day{
      Monday = 0,
      Tuesday,
      Wensday,
        }
    }
    //引用
    NS::day::Wensday

    int a,b;

    char c[10];

    cin(a,b);  //从屏幕接受两个变量,类似scanf

    cin.getline(c,10);  //从屏幕接受一个字符串,长度为10,getline只能为接受字符串!!!

    typedef

      typedef int type;
        type b,c;
        b=10;
    
        cout<<b<<endl;    //output: 10

    printf字符串和字符的输出,

    char t[10] = {'a','b'};
    printf("%s",t);
    printf("%c",t[0]);

  • 相关阅读:
    封装tip控件
    Javascirpt中创建对象的几种方式
    使用Servlet上传文件
    Struts2 基本配置
    使用JQuery实现手风琴布局
    winform下自绘提示框风格窗体
    环形进度条
    Oracle中获取当前时间半小时前的时间
    JSTL+MyEclipse8.5+Tomcat配置
    使用CSS和jQuery实现对话框
  • 原文地址:https://www.cnblogs.com/alazalazalaz/p/4071497.html
Copyright © 2011-2022 走看看