1 |
#pragma warning(disable:4996) |
- Clean code deveopment: http://lumiera.org/project/background/CleanCodeDevelopment.html
* [http://www.cplusplus.com/doc/tutorial Here] is a great C/C++ tutorial.
* [http://www.thegeekstuff.com/2012/08/gprof-tutorial/ GPROF Tutorial – How to use Linux GNU GCC Profiling Tool]
==Style==
*Clean code deveopment: http://lumiera.org/project/background/CleanCodeDevelopment.html
==Warning==
#pragma warning(disable:4996)
==PCH==
# Right-click on your project in the Solution Explorer.
# Click Properties at the bottom of the drop-down menu.
# At the top left of the Properties Pages, select All Configurations from the drop-down menu.
# Open the C/C++ tree and select Precompiled Headers
# Precompiled Header: Select Use (/Yu)
# Fill in the Precompiled Header File field. Standard is stdafx.h
# Click Okay
# If you do not have stdafx.h in your Header Files put it there. Edit it to #include all the headers you want precompiled.
# Put a file named stdafx.cpp into your project. Put #include “stdafx.h” at the top of it, and nothing else.
# Right-click on stdafx.cpp in Solution Explorer. Select Properties and All configurations again as in step 4 …
# but this time select Precompiled Header Create (/Yc). This will only bind to the one file stdafx.cpp.
# Put #include “stdafx.h” at the very top of all your source files. (Unix or cygwin users: find . -name “*.cpp” | xargs -n1 sed -i ‘1s/^/#include “stdafx.h”\n/’)
# Lucky 13. Cross your fingers and hit Build.
==Debug==
*[http://blog.ruofeidu.com/measure-execution-time-c-11/ DebugTimer: How to Measure Execution Time in C++ 11]
==Loops==
with vector
for (const auto& img : imgs) {
imgs_bak.push_back(img);
}
==IO==
* [http://phoenix.goucher.edu/~kelliher/cs43/mar26.html Low-Level File I/O in C]
1 |
count = fread(&zoffset_, sizeof(decltype(zoffset_)), 1, fp); |
===Binary===
1 2 3 4 5 |
FILE * pFile; char buffer[] = { 'x' , 'y' , 'z' }; pFile = fopen ("myfile.bin", "wb"); fwrite (buffer , sizeof(char), sizeof(buffer), pFile); fclose (pFile); |
==Enum==
1 2 3 4 |
enum class Color {RED, GREEN, BLUE}; enum class Feelings {EXCITED, MOODY, BLUE}; #include <cstdint> enum class Colors : std::int8_t { RED = 1, GREEN = 2, BLUE = 3 }; |
==Lambda==
1 2 3 4 5 |
auto lambda = [](auto x, auto y) {return x + y;}; // C++14 auto lambda = [](int x, int y) {return x + y;}; // C++11 std::unique_ptr ptr(new int(10)); auto lambda = [value = std::move(ptr)] {return *value;}; |
==Function List==
1 2 3 4 |
vector<function<int(int)>> funlist; for(int i = 0; i < 10; i++) funlist.push_back([=](int j){return i+j;}); cout << funlist[5](8) << endl; |
==Numbers==
1 2 3 4 5 6 7 8 9 10 11 |
int main() { int val = 0b11110000; std::cout << "Output mask: " << 0b1000'0001'1000'0000 << "\n"; std::cout << "Proposed salary: $" << 300'000.00 << "\n"; return 0; } |
==Debug==
1 2 3 4 5 |
[[deprecated("Consider using something other than cranky")]] int cranky() { return 0; } |
==References==
*[https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html Common Predefined C/C++ Macros]
Leave a Reply