Yao Lirong's Blog

C++ Manual

2020/11/29
  • char :1个字节
  • char*(即指针变量): 8个字节
  • short int : 2个字节
  • int: 4个字节
  • unsigned int : 4个字节
  • float: 4个字节
  • double: 8个字节
  • long: 8个字节
  • long long: 8个字节
  • unsigned long: 8个字节

I/O

读入字符串可以用 scanf("%s")getline()

读入字符且忽略空格可以用 scanf(" %c"),注意 %c 前面的空格

Class and Header

It is not possible to create an instance of a class without invoking the constructor

STL的使用

指针的使用

类与结构体的使用

String

  • Split a String: strtok: Reference 1, Reference 2

    1
    2
    3
    4
    5
    6
    7
    8
    9
    char str[] ="- This, a sample string.";
    char * pch;
    pch = strtok (str," ,.-");
    while (pch != NULL)
    {
    printf ("%s\n",pch);
    // Note to use NULL the next time you call strtok
    pch = strtok (NULL, " ,.-");
    }
  • Convert a char array to integer: sscanf(s, "%i", &imm) automatically detects whether s is an decimal 142 or a hex 0xa2c (Note the 0x before a hex number is necessary)

    1
    2
    3
    char myarray[5] = {'-', '1', '2', '3', '\0'};
    int i;
    sscanf(myarray, "%d", &i);
  • Read in both hex and dec number: scanf("%i", )

  • Strings in C (char arrays) end with a terminating null-character '\0'

其它问题

CATALOG
  1. 1. I/O
  2. 2. Class and Header
  3. 3. STL的使用
  4. 4. 指针的使用
  5. 5. 类与结构体的使用
  6. 6. String
  7. 7. 其它问题