How to print Content of currently Executing file C++?

How to print all the content of the currently executing file from in itself in C++?

#include <iostream>
using namespace std;

int main() {
    // some code that print current file.
}

expected output:

#include <iostream>
using namespace std;

int main() {
    // some code that print current file.
}

Answer

there can be many ways possible, easy one.

#include <iostream>
using namespace std;

int main() {
    string more = "more ";
    more.append(__FILE__);
    system(more.c_str());

}

Output:

#include <iostream>
using namespace std;

int main() {
    string more = "more ";
    more.append(__FILE__);
    system(more.c_str());

}

Leave a Reply

Your email address will not be published. Required fields are marked *