Skip to content

C++ Primer

A deficient skyscraper engenders catastrophic consequences for the overall infrastructure.Consequently, the process of reacquainting oneself with the intricacies of C++ is an inevitable undertaking in the life of an algorithm engineer. Thus, it is advisable to desist from excessive discourse and instead focus on the practical implementation of the code.

The organization of the note diverges from that of the book, owing to the fact that a substantial portion of the knowledge I had previously acquired remains ingrained in my understanding.


I. Basic

2 Variables and Basic types

  • [ ] Basic Variable types and their storage

  • [ ] Type Conversions

    screenshot 2023-09-08 at 2.15.45 PM

    In truncate part, will conversions be time-consuming? Considering that a double was calculated by the powers of 2, how can you convert?

  • [ ] When a type is unsigned, what is its range

  • [ ] Discuss the relationship between literals and typesscreenshot 2023-09-08 at 2.12.57 PM

  • [ ] WTF is a wide character. Wide characters' literals are L'a'

screenshot 2023-09-08 at 2.25.38 PM

This Warning is quite touching to me 'cause no one had ever noticed me of before.

3 Strings Vectors and Arrays

Strings and Vectors are widely used. String can be initialized in several ways.

3.1 Namespace

3.2 String

You can treat strings like basic types or objects(be careful not to use {})

It's pretty tricky that concatenating string using "" , remembering left hand assign rule.

Strings has size() and empty(), not isempty(). ehhh..

screenshot 2023-09-10 at 9.05.17 PM

The reason is listed below:

screenshot 2023-09-10 at 9.09.12 PM

Literals matter.

decltype(type) good stuff if you don't know witch type.

To iterate char in string, copy/ change is different.

screenshot 2023-09-10 at 9.23.13 PM

screenshot 2023-09-10 at 9.23.24 PM

String table:

screenshot 2023-09-10 at 9.28.42 PM

3.3 Vectors

I LOVE VECTORS

screenshot 2023-09-10 at 9.41.11 PM

push_back() makes a copy of the element.

screenshot 2023-09-10 at 10.00.44 PM

This reminds me of Index Out of Bound in Java.

3.4 Iterator

Iterators are representatives of generic thinkings.

  • auto
  • ++
  • *

Any Pointer(maybe ref) overloading * and ++ would be a iterator.

screenshot 2023-09-10 at 10.39.04 PM

screenshot 2023-09-10 at 10.33.03 PM

3.5 Arrays

The diff between arrays and vectors is that arrays have fixed size.

Thus, intuitively, arrays sometimes performs better than vectors.

3.6 Multi-D arrays

I've never seen of any code using multi-d arrays in c++.

It's because it's insufficient.

Like this explanation very much.