2

I created the following C++ snippet in VS Code.

/**
 *       Author :   Sakib62
 *       Created:   Fri__01.Jul.2022__03:59:25
 *       File   :   3.cpp
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
    
}

I added Current time and date in the snippet taking help from VScode Docs.

So, when I trigger the snippet, I get creation time of the file. But I also want to get the last modified date & time every time I save the file or edit.

I want the snippet to be like:

/**
 *       Author :   Sakib62
 *       Created:   Fri__01.Jul.2022__03:59:25
 *       Last Modified: Fri__01.Jul.2022__04:42:13
 *       File   :   3.cpp
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
    //code
}

How can I do it??

user4581301
  • 33,082
  • 7
  • 33
  • 54
Sakib62
  • 21
  • 4
  • 1
    `#include using namespace std;` Why are you doing that? – Paul Sanders Jun 30 '22 at 22:53
  • It's a template for Competitive Programming Contest where instead of writing separate header file, using all at once is time efficient. – Sakib62 Jun 30 '22 at 23:00
  • Whose time are we talking about here? – Paul Sanders Jun 30 '22 at 23:01
  • System time. Or my Device time I guess. – Sakib62 Jun 30 '22 at 23:02
  • 2
    Unless you have your build system rigged to use pecompiled headers, including the entire C++ Standard library SLOWS your build times by about an order of magnitude. This means every time you build the program, you lose time. Unless you're a slow typist, usually 2-3 builds soaks up all the time you saved typing only one include directive. After that it's costing you development time. There should be no change to runtime with the correct headers or all the headers. – user4581301 Jun 30 '22 at 23:13
  • 1
    Outside of competitive programming, `#include using namespace std;` is a warning that you may be dealing with someone who's style is overly lax and may need some remedial work, or a cargo cultist wo doesn't really know what they're doing. Be careful when using it in code samples or job interviews. – user4581301 Jun 30 '22 at 23:18
  • 1
    A question: What triggers the snippet? Does it automatically update when the file is saved? If not, what you're trying to do isn't all that useful. All you'll record is the last time the field was updated. Back when I was doing stuff like this, as opposed to just using the logging features of whatever repository software I was using, I'd have a hook installed to update the header with the revision number and commit time every time a file was checked out or updated. I stopped doing this because the extra noise in diffs was more annoying than the header was useful. – user4581301 Jun 30 '22 at 23:29
  • Good question, though. – user4581301 Jun 30 '22 at 23:32
  • Thanks for your tips and information. I use precompiled header file. But I will try to use separate header files. Snippets do not update when the file is saved as far as I know. I had an idea about implementing a snippet just for Last Modified Time. I can use keybinding (ctrl+s) to that snippet. So every time I save by (ctrl+s), the snippet will replace itself with current time. The problem is if a snippet is triggered by a keybinding or a keyword, it is placed at the position where the cursor is. But I want the snippet in top of my code no matter where my cursor is. – Sakib62 Jul 01 '22 at 01:21

0 Answers0