Skip to content

Update show.ts #996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ async function showProblemInternal(node: IProblem): Promise<void> {
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 <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`;
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,
Expand Down