Skip to content

Commit edabef5

Browse files
authored
cpp_tips: address review comments
#1383
1 parent 0c589a4 commit edabef5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/others/cpp_tips.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tags:
77

88
## Faster I/O
99

10-
- `std::ios_base::sync_with_stdio(false)`: by default, C++ works with C++ iostreams (like `std::cin`) and C style stdio streams (like `stdin`) by synchronizing them.
10+
- `std::ios_base::sync_with_stdio(false)`: by default, C++ works with C++ iostreams (like `std::cin`, may not apply to new C++23 `std::print`/`std::println`) and C style stdio streams (like `stdin`) by synchronizing them.
1111
Since you should never need C style I/O (like `scanf`, `printf`), in C++, disabling this synchronization will make C++ I/O competitive with C style `scanf`.
1212
- `std::cin.tie(0)`: By default, iostreams flush cout every time you read from cin, so that you will always display any output before reading any input.
1313
You can disable this automatic flushing to make I/O faster. The exception is for interactive problems with interleaved inputs and outputs, for which you can either not use `cin.tie(0)` or flush explicitly with `cout.flush()`/`cout.endl`.
@@ -19,9 +19,9 @@ References:
1919
## Less Typing
2020

2121
- `using namespace std;`: this saves lots of tedious typing of `std::` before all the standard library functions and objects. However, a blanket namespace import like this can cause name clashes, so don't name your variables or functions something common like `find` or anything from [this list](https://en.cppreference.com/w/cpp/symbol_index).
22-
- `#include <bits/stdc++.h>`: this is a catch-all implementation-defined header in g++ that avoids having a list of dozens of includes like `#include <vector>`, `#include <iostream>`, `#include <string>`, etc. It should work on any CP judge site, but it is not a standard header.
23-
- `#define int long long`: some people define `int` to always be (at least) 64-bit to avoid overflow issues, since most CP problems use numbers that fit in a 64-bit integer. However, be aware of unexpected issues:
22+
- `#include <bits/stdc++.h>`: this is a catch-all implementation-defined header in g++ that avoids having a list of dozens of includes like `#include <vector>`, `#include <iostream>`, `#include <string>`, etc. It should work on any CP judge site, but it is not a standard header. On your local machine, it can be pre-compiled to greatly save compilation time.
23+
- `#define int long long`: some people define `int` to always be (at least) 64-bit to avoid overflow issues, since most CP problems use numbers that fit in a 64-bit integer. However, this is **not recommended** because of many unexpected issues:
2424
- C++ requires `main` to be a function returning `int` and not `long long`, so use `signed main` as a workaround.
2525
- Function calls like `min(x, 0)` may complain that `0` is type `int`.
26-
- May require twice as much memory than `int` and make the program slower, which may be important in extremely time-critical code.
26+
- Requires twice as much memory than `int` and may make the program slower, which may be important in extremely time-critical code.
2727
- Otherwise you can use `typedef long long ll` or use the appropriate fixed-width integer types like `int64_t`.

0 commit comments

Comments
 (0)