Open Current Source File
tuhuuduc
c_cpp
2 years ago
518 B
9
Indexable
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream file(__FILE__); // Open the current source file
std::string line;
if (file.is_open()) {
// Read and print each line of the source file
while (std::getline(file, line)) {
std::cout << line << std::endl;
}
file.close(); // Close the file
} else {
std::cerr << "Failed to open source file." << std::endl;
return 1;
}
return 0;
}
Editor is loading...
Leave a Comment