I am using clang-format extension in vscode to format my c++ code. I was looking for a configuration that could add a single empty line as the last line in the code. But found none.
If I have a case:
#include <iostream>
using namespace std;
int main() {
string s = "asfasdf";
cout << "Type IIanything: ";
// cin >> s;
for (int i = s.length() - 1; i > -1; i--) {
cout << s[i];
}
cout << endl;
cout << "NOT using build 2" << endl;
}
---empty line1---
---empty line2---
---empty line3---
Then when i hit save, the empty line 2 and 3 rows are gone. And only 1 is left. This is fine for me. But if none of 1, 2 and 3 were there, and i hit save, the closing brace is the last line in the code. What can i do to add an empty line after the closing brace in such a situation.
Adding the following two entries to your settings.json
should fix it:
{
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}
This will cause VS Code to either insert a final newline if none is present, or trim multiple final newlines so only one is present.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With