显示文件当前路径

来源:百度知道 编辑:UC知道 时间:2024/06/01 22:50:23
#include<iostream>
using namespace std;

void main()
{
cout<<__FILE__<<endl;
cout<<__TIME__<<" "<<__DATE__<<endl;
}
简简单单的一个程序,显示当前文件全路径和当前日期和时间的。
但是,生成的exe文件移植到其他地方,每次都运行得到第一次运行显示的东西。需要做哪些修改,才能得到不同地方显示不同结果呢?求救中。。。

1.打开我的电脑
2.选择"工具"\文件夹选项
3.选择“查看”
4.选择"高级设置"中的在地址栏显示全部路径。

这些宏都是调试时候用的着的,编绎后直接被替换成常量字符串。
__TIME__ ,__DATE__都是调试时的时间和日期
The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library function asctime declared in TIME.H.
The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks.

可以调用win-api来得到当前程序的路径:
DWORD GetCurrentDirectory(DWORD nBufferLength,LPTSTR lpBuffer);
Parameters
nBufferLength
The length of the buffer for the current directory string, in TCHARs. The buffer length must include room for a terminating null character.

lpBuffer
A pointer to the buffer that receives the current directory string. This null-terminated string specifies the absolute path to the current directory.

To determine the required bu