Something about CPP

本文提供了C++编程学习路径及技巧,强调实践的重要性,并通过具体示例讲解如何使用标准库和调试工具理解程序运行机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载请注明:http://blog.youkuaiyun.com/c602273091/article/details/50441325

Long time no see, old guys!(means C++)

Useful Warning
计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……

对学习编程者的忠告:
眼过千遍不如手过一遍!
书看千行不如手敲一行!
手敲千行不如单步一行!
单步源代码千行不如单步对应汇编一行!

单步类的实例“构造”或“复制”或“作为函数参数”或“作为函数返回值返回”或“参加各种运算”或“退出作用域”的语句对应的汇编代码几步后,就会来到该类的“构造函数”或“复制构造函数”或“运算符重载”或“析构函数”对应的C/C++源代码处。

VC调试时按Alt+8、Alt+7、Alt+6和Alt+5,打开汇编窗口、堆栈窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应堆栈、内存和寄存器变化,这样过一遍不就啥都明白了吗。

对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。

http://bbs.youkuaiyun.com/topics/390498451

Undefined Meaning
In c++ STL, there is hash function, so don’t define a global variable named hash.

#include <iostream>
#include <string>
#include <functional>

int main()
{
    std::string s = "Stand back! I've got jimmies!";
    std::hash<std::string> hash_fn;

    size_t hash = hash_fn(s);

    std::cout << hash << '\n';
}

http://en.cppreference.com/w/cpp/string/basic_string/hash

string
When using getline, if undefined, using include “string”

Key Word

http://www.cnblogs.com/fanzhidongyzby/archive/2012/11/07/2759326.html

Marco

#if SVC_EXTENSION
#include <vector>
#define NV_VERSION        "7.0 (HM-15.0)"                 ///< Current software version
#else
#define NV_VERSION        "15.0"                ///< Current software version
#endif

OS Bits

#define NVM_BITS          "[%d bit] ", (sizeof(void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S

File Operation

  fstream bitstreamFile(m_pBitstreamFile, fstream::binary | fstream::out);
  if (!bitstreamFile)
  {
    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pBitstreamFile);
    exit(EXIT_FAILURE);
  }
#if EFFICIENT_FIELD_IRAP
  Int IRAPGOPid = -1;
  Bool IRAPtoReorder = false;
  Bool swapIRAPForward = false;
  if(isField)
  {
    Int pocCurr;
#if SVC_EXTENSION
    for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ )
#else
    for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
#endif  

http://blog.youkuaiyun.com/bichenggui/article/details/4600153

Transition between Char* and string

http://www.cnblogs.com/zhixing/archive/2013/06/04/3116814.html

Stack Usage

http://www.169it.com/article/2839007600903800247.html

Read Blank Whole Sentence

http://zhidao.baidu.com/question/417237674.html

Bracket Matching

#include<iostream>
#include<cstring>
#include<string.h>
#include<iostream>
#include<stack>
#include<string>
#include<stdio.h>

using namespace std;

bool brackets(string s){
    stack<char> st;
    stack<char> tempStack;

    int length;
    length = s.length();
    int j = 0;
    char symbol;
    char temp;
    bool ab = true;

    for (j = 0; j<length; j++){
        symbol = s[j];
        if (symbol == '{' || symbol == '[' || symbol == '('){
            st.push(symbol);
        }
        if (symbol == '}' || symbol == ']' || symbol == ')'){
            if (st.empty())
                return false;
            while (!st.empty())
            {
                temp = st.top();
                st.pop();
                if ((symbol == '}'&& temp == '{') || (symbol == ']'&& temp == '[') || (symbol == ')'&& temp == '('))
                {
                    while (!tempStack.empty())
                    {
                        temp = tempStack.top();
                        tempStack.pop();
                        st.push(temp);
                    }
                    break;
                }
                else if (st.empty())
                {
                    return false;
                }
                else
                {
                    tempStack.push(temp);
                }
            }
        }
    }
    if (!st.empty()) return false;
    else
        return true;
}

int main(){
    int n;
    cin >> n;
    getchar();
    for (int i = 0; i<n; i++){
        char ch[1001];

        gets(ch);

        string s(ch);

        cout << ch << endl;

        //string ch;
        //cin >> ch;
        bool flag = brackets(s);
        if (flag == true){
            cout << "Yes" << endl;
        }
        if (flag == false){
            cout << "No" << endl;
        }
    }
    return 0;
}

headfile macro

#ifndef _STDIO_H_ 
#define _STDIO_H_ 

...... 

#endif

stdint

#ifndef __STDINT_H
#define __STDINT_H

/* 7.18.1.1 Exact-width integer types */

typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;

typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;



/* 7.18.1.2 Minimum-width integer types */

typedef __int8 int_least8_t;
typedef __int16 int_least16_t;
typedef __int32 int_least32_t;
typedef __int64 int_least64_t;

typedef unsigned __int8 uint_least8_t;
typedef unsigned __int16 uint_least16_t;
typedef unsigned __int32 uint_least32_t;
typedef unsigned __int64 uint_least64_t;



/* 7.18.1.3 Fastest minimum-width integer types */

typedef __int8 int_fast8_t;
typedef __int16 int_fast16_t;
typedef __int32 int_fast32_t;
typedef __int64 int_fast64_t;

typedef unsigned __int8 uint_fast8_t;
typedef unsigned __int16 uint_fast16_t;
typedef unsigned __int32 uint_fast32_t;
typedef unsigned __int64 uint_fast64_t;



/* 7.18.1.4 Integer types capable of holding object pointers */

typedef int32_t intptr_t;
typedef uint32_t uintptr_t;



/* 7.18.1.5 Greatest-width integer types */

typedef int64_t intmax_t;
typedef uint64_t uintmax_t;



/* 7.18.2.1 Limits of exact-width integer types */

#define INT8_MIN ((int8_t) -128)
#define INT16_MIN ((int16_t) -32768)
#define INT32_MIN ((int32_t) -2147483648)
#define INT64_MIN ((int64_t) -9223372036854775808)

#define INT8_MAX ((int8_t) 127)
#define INT16_MAX ((int16_t) 32767)
#define INT32_MAX ((int32_t) 2147483647)
#define INT64_MAX ((int64_t) 9223372036854775807)

#define UINT8_MAX ((uint8_t) 255)
#define UINT16_MAX ((uint16_t) 65535)
#define UINT32_MAX ((uint32_t) 4294967295)
#define UINT64_MAX ((uint64_t) 18446744073709551615)



/* 7.18.2.2 Limits of minimum-width integer types */

#define INT_LEAST8_MIN ((int_least8_t) -128)
#define INT_LEAST16_MIN ((int_least16_t) -32768)
#define INT_LEAST32_MIN ((int_least32_t) -2147483648)
#define INT_LEAST64_MIN ((int_least64_t) -9223372036854775808)

#define INT_LEAST8_MAX ((int_least8_t) 127)
#define INT_LEAST16_MAX ((int_least16_t) 32767)
#define INT_LEAST32_MAX ((int_least32_t) 2147483647)
#define INT_LEAST64_MAX ((int_least64_t) 9223372036854775807)

#define UINT_LEAST8_MAX ((uint_least8_t) 255)
#define UINT_LEAST16_MAX ((uint_least16_t) 65535)
#define UINT_LEAST32_MAX ((uint_least32_t) 4294967295)
#define UINT_LEAST64_MAX ((uint_least64_t) 18446744073709551615)



/* 7.18.2.3 Limits of fastest minimum-width integer types */

#define INT_FAST8_MIN ((int_fast8_t) -128)
#define INT_FAST16_MIN ((int_fast16_t) -32768)
#define INT_FAST32_MIN ((int_fast32_t) -2147483648)
#define INT_FAST64_MIN ((int_fast64_t) -9223372036854775808)

#define INT_FAST8_MAX ((int_fast8_t) 127)
#define INT_FAST16_MAX ((int_fast16_t) 32767)
#define INT_FAST32_MAX ((int_fast32_t) 2147483647)
#define INT_FAST64_MAX ((int_fast64_t) 9223372036854775807)

#define UINT_FAST8_MAX ((uint_fast8_t) 255)
#define UINT_FAST16_MAX ((uint_fast16_t) 65535)
#define UINT_FAST32_MAX ((uint_fast32_t) 4294967295)
#define UINT_FAST64_MAX ((uint_fast64_t) 18446744073709551615)



/* 7.18.2.4 Limits of integer types capable of holding object pointers */

#define INTPTR_MIN ((intptr_t) -32768)
#define INTPTR_MAX ((intptr_t) 32767)
#define UINTPTR_MAX ((intptr_t) 65535)



/* 7.18.2.5 Limits of greatest-width integer types */

#define INTMAX_MIN ((intmax_t) -9223372036854775808)
#define INTMAX_MAX ((intmax_t) 9223372036854775807)
#define UINTMAX_MAX ((uintmax_t) 18446744073709551615)



/* 7.18.3 Limits of other integer types */

#define PTRDIFF_MIN ((int32_t) -65536)
#define PTRDIFF_MAX ((int32_t) 65535)

#ifdef __STDC_LIMIT_MACROS
#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX
#endif

#define SIZE_MAX 65535

#ifdef __STDC_CONSTANT_MACROS
#define WCHAR_MIN INT16_MIN
#define WCHAR_MAX INT16_MAX
#define WINT_MIN INT16_MIN
#define WINT_MAX INT16_MAX
#endif



/* 7.18.4.1 Macros for minimum-width integer constants */

#define INT8_C(x) ((int8_t) x)
#define INT16_C(x) ((int16_t) x)
#define INT32_C(x) ((int32_t) x)
#define INT64_C(x) ((int64_t) x)

#define UINT8_C(x) ((uint8_t) x)
#define UINT16_C(x) ((uint16_t) x)
#define UINT32_C(x) ((uint32_t) x)
#define UINT64_C(x) ((uint64_t) x)



/* 7.18.4.2 Macros for greatest-width integer constants */

#define INTMAX_C(x) ((intmax_t) x)
#define UINTMAX_C(x) ((uintmax_t) x)

#endif /* __STDINT_H */

http://bbs.youkuaiyun.com/topics/330246620

Hehe, too easy!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值