Skip to content

Commit 748223c

Browse files
authored
Update show.ts
Adding cpp headers for easy debugging
1 parent 586b3e4 commit 748223c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/commands/show.ts

+7
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ async function showProblemInternal(node: IProblem): Promise<void> {
191191
const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
192192

193193
await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation);
194+
// Add C++ headers and main function if the language is C++
195+
if (language === "cpp") {
196+
const cppHeaders = `#include <iostream>\n#include <vector>\n#include <string>\n#include <algorithm>\n#include <map>\n#include <set>\n#include <queue>\n#include <stack>\n#include <deque>\n#include <unordered_map>\n#include <unordered_set>\n#include <cmath>\n#include <numeric>\n#include <functional>\n#include <iomanip>\n#include <sstream>\n#include <bitset>\n#include <climits>\n#include <cstring>\n#include <cassert>\nusing namespace std;\n\n`;
197+
const mainFunction = `int main() {\n Solution sol;\n // Add your test cases here\n cout << "Test cases go here" << endl;\n return 0;\n}\n`;
198+
const fileContent = yield vscode.workspace.fs.readFile(vscode.Uri.file(finalPath));
199+
yield vscode.workspace.fs.writeFile(vscode.Uri.file(finalPath), Buffer.from(cppHeaders + fileContent.toString() + "\n" + mainFunction));
200+
}
194201
const promises: any[] = [
195202
vscode.window.showTextDocument(vscode.Uri.file(finalPath), {
196203
preview: false,

0 commit comments

Comments
 (0)