1. cin vs getline vs cin.getline

    cin vs getline vs cin.getline

    Case with '\n'

    cin

    drop all `'\n'` except last one (just leave it in the buffer,won't get it and will finally drop it).
    

    getline

    read until `'\n'` and replace `'\n'` with `'\0'`.
    

    cin.getline

    same with getline, replace `'\n'` with `'\0'`.
    
    but …
    Tagged as : C++ program
  2. strlen_analyze

    #include <iostream>
    
    #include <vector>
    
    #include <string>
    
    #include <stack>
    #include <ctime>
    #include <windows.h>
    
    const int n = 1024*1024*500;
    
    using namespace std;
    class timer
    {
        long long t;
    
      public:
        timer()
        {
            t = clock();
        }
        ~timer()
        {
            cout << clock() - t << endl;
        }
    };
    size_t strlen1(const char *str)
    {
        register int length = 0;
    
        while (*str++)
    
            ++length;
    
        return (length …
    Tagged as : program analyze

Pages