一个关于文件路径的有关问题

一个关于文件路径的问题
在程序里想获取当前生成的可执行文件的路径,在该路径下,创建一个文本文件。
我直接写     ifstream   filename;
                      filename.open(文件名,ios::in|ios::binary);
在程序里对该文件进行操作,
这个文件名怎么写才会在可执行文件的路径下生成呢?


------解决方案--------------------
几个错误,
写/创建文件用ofstream.
文本文件不一定需要ios::binary。

iclx012$ more 4.c
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ofstream filename( "./tmp.out ", ios::out|ios::binary);
filename < < "hello " < <endl;
filename.close();
}
iclx012$ g++ 4.c
iclx012$ ./a.out
iclx012$ more ./tmp.out
hello
iclx012$
------解决方案--------------------
使用默认方式即可
------解决方案--------------------
filename.open( "test.txt ",ios::in|ios::binary);

文件参数不使用绝对路径,
其表达的意义就是相对于该exe运行时候路径的一个 相对路径,
也就是当前目录下生成的。
------解决方案--------------------
char strCurDir[_MAX_PATH];
_getcwd(strCurDir, _MAX_PATH);
char strFileName[] = "test.txt ";
char strPath[_MAX_PATH];
strcpy(strPath, strCurDir);
strcat(strPath, strFileName);
filename.open(strPath....);