本文介绍了如何发现当前目录的完整路径名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我写了一段与Postgres接口的代码。将Postgres表写入磁盘需要 ,它与< COPYcom- 命令一起使用。该命令要求写入文件的绝对文件名为 。现在我把它硬编码到确切的位置 我想要它,但那不是很便携。在C 中是否有某种方法来检索当前目录的绝对路径名,这样我就可以在我的代码中使用它,因此我的代码功能正确无 问题在哪里执行?任何有关这方面的信息都会非常感激。 --- Kevin Simonson 你如果你不相信那里的话,就永远不会去天堂,甚至不去洛杉矶。 。来自_Why Not_I''ve written a piece of code that interfaces with Postgres. It needsto write a Postgres table to disk, which it does with the <COPYcom-mand. That command requires the absolute file name of the file beingwritten to. Right now I''ve got it hard coded to the exact locationwhere I want it, but that''s not very portable. Is there some way in Cto retrieve the absolute path name of the current directory, so that Icould use that in my code and therefore have my code function right nomatter where it''s executed? Any information on this would be greatlyappreciated.---Kevin Simonson"You''ll never get to heaven, or even to LA,if you don''t believe there''s a way."from _Why Not_推荐答案 在标准C中没有可移植的方法:事实上,C本身 什么都不知道所有关于目录。但是所有运行的b $ b系统都提供了一种方法。例如,unix系统具有 getcwd()(获取当前工作目录),该声明在 < unistd.h>中声明。 - Richard - 需要考虑多达32个字符 在一些字母表中 - 1963年的X3.4。There''s no portable way to do this in standard C: in fact, C itselfdoesn''t know anything at all about directories. But all operatingsystems provide a way to do it. For example, unix systems havegetcwd() ("get current working directory") which is declared in<unistd.h>.-- Richard--"Consideration shall be given to the need for as many as 32 charactersin some alphabets" - X3.4, 1963. 所有操作系统_这首先是可能的。它总是不可能是;例如,在早期版本的MS-DOS下, 没有目录这样的东西。所有常见的现代桌面操作系统 都有它们,但我不会感到惊讶所有学习嵌入式的 有文件但没有目录,因此没有路径名, 绝对或相对。 RichardAll operating systems _where this is possible in the first place_. It isnot always possible; for example, under very early versions of MS-DOS,there was no such thing as a directory. All common modern desktop OSeshave them, but I would not be surprised at all to learn of embedded onesthat have files, but no directories, and therefore no path names,absolute or relative.Richard 这篇关于如何发现当前目录的完整路径名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 17:20