Short C++ Notes on check if a file exists, string concatenation, vector

Short C++ Notes on check if a file exists, string concatenation, vector

  1. To check if a file exists, the best way is to use stat, however, sometimes this can be problematic (some say when a file is larger than 2 GB). I haven’t run into that particular problem yet.
    1. Good post http://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c  . I specially like the listing of all 4 methods and benchmark them.
  2. Concatenate string <string.h> and convert integer to string
    1. It turns out that C++ string utility is pretty useful. You can simply do A + B to concatenate two string.
    2. However, to use a char* type, you need to do string.c_str() with <cstring> included.
    3. To convert an integer to string, try this trick
      1. std::to_string(integer)
  3. Vector with push back is very slow, try using an integer array with a dynamic index.
Advertisements
This entry was posted in Tools and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s