-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler.cpp
58 lines (53 loc) · 1.63 KB
/
compiler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream> // For file operations
// Function to compile a C++ source file
bool compile(const std::string &filename)
{
std::string compileCommand = "g++ " + filename + " -o output"; // Adjust as needed
int result = std::system(compileCommand.c_str());
return (result == 0);
}
// Function to run an executable
void run(const std::string &filename)
{
std::string runCommand = ".\\" + filename + ".exe ";
std::system(runCommand.c_str());
}
void run_in_another_window(const std::string &filename)
{
#ifdef _WIN32 // Windows
std::string runCommand = "start cmd /c \"" + filename + " & pause\"";
#elif __linux__ // Linux
std::string runCommand = "x-terminal-emulator -e \"" + filename + "; read -n 1 -s -r -p 'Press any key to continue...'\"";
#elif __APPLE__ // macOS
std::string runCommand = "osascript -e 'tell application \"Terminal\" to do script \"" + filename + "\"'";
#else
std::cerr << "Unsupported operating system." << std::endl;
return;
#endif
std::system(runCommand.c_str());
}
// Function to "debug" (simulated basic debugging)
void debug(const std::string &filename)
{
std::cout << "Debugging " << filename << " (simulated):\n";
std::ifstream file(filename);
if (file.is_open())
{
std::string line;
int lineNumber = 1;
while (std::getline(file, line))
{
std::cout << lineNumber << ": " << line << std::endl;
lineNumber++;
}
file.close();
}
else
{
std::cerr << "Unable to open file for debugging." << std::endl;
}
}