diff --git a/src/commands/show.ts b/src/commands/show.ts index eccf557..974c9af 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -191,6 +191,13 @@ async function showProblemInternal(node: IProblem): Promise { const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation(); await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation); + // Add C++ headers and main function if the language is C++ + if (language === "cpp") { + const cppHeaders = `#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n`; + 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`; + const fileContent = yield vscode.workspace.fs.readFile(vscode.Uri.file(finalPath)); + yield vscode.workspace.fs.writeFile(vscode.Uri.file(finalPath), Buffer.from(cppHeaders + fileContent.toString() + "\n" + mainFunction)); + } const promises: any[] = [ vscode.window.showTextDocument(vscode.Uri.file(finalPath), { preview: false, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy