With VC, I have used this in the past:
#define STRINGIFY( L ) #L
#define MAKESTRING( M, L ) M(L)
#define SHOWORIGIN __FILE__ "("MAKESTRING( STRINGIFY, __LINE__) "): "
// then, later...
#pragma message( SHOWORIGIN "we need to look at this code" )
// ...
#pragma message( SHOWORIGIN "and at this, too" )
Output:
c:\...\test.cpp(8): we need to look at this code
c:\...\test.cpp(10): and at this, too
You can double-click on it in the output pane and the IDE takes you to the right file and line.