Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get current file path in c++? [duplicate]

Tags:

c++

I want get current file path,like in a.cpp,I can get

/home/workspace/src/a.cpp

How can I get this path?

like image 396
Daniel Lee Avatar asked Jan 17 '26 21:01

Daniel Lee


1 Answers

You can use the standard macro __FILE__ to which expands to a string literal that contains the path of the current source file.

Starting from C++20, you can use default constructed std::source_location.

like image 200
eerorika Avatar answered Jan 20 '26 10:01

eerorika