本文介绍了有一个C ++等同于getcwd吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到C的getcwd通过:
man 3 cwd



我怀疑C ++有一个类似的,可以返回一个std :: string。 / p>

如果是这样,它叫什么,我在哪里可以找到它的文档?



谢谢! >

解决方案

好,我回答了,即使你已经接受了答案。



比封装getcwd调用更好的方法是使用,其中从<$ c $>获得路径 c> current_path()函数。 Boost文件系统库允许你做很多其他有用的东西,否则你需要做很多字符串解析,例如检查文件/目录是否存在,获取父路径,使路径完成etcetera。检查出来,它是便携式的 - 这很大一部分字符串解析代码否则将可能不会使用。



更新(2016) :文件系统在2015年发布为,基于on Boost文件系统v3。这意味着它可能已经与您的编译器一起使用(例如Visual Studio 2015)。对我来说,它似乎也可能成为未来C ++标准的一部分(我假设C ++ 17,但我不知道当前的状态)。


I see C's getcwd via:man 3 cwd

I suspect C++ has a similar one, that could return me a std::string .

If so, what is it called, and where can I find it's documentation?

Thanks!

解决方案

Ok, I'm answering even though you already have accepted an answer.

An even better way than to wrap the getcwd call would be to use boost::filesystem, where you get a path object from the current_path() function. The Boost filesystem library allows you to do lots of other useful stuff that you would otherwise need to do a lot of string parsing to do, like checking if files/directories exist, get parent path, make paths complete etcetera. Check it out, it is portable as well - which a lot of the string parsing code one would otherwise use likely won't be.

Update (2016): Filesystem has been published as a technical specification in 2015, based on Boost Filesystem v3. This means that it may be available with your compiler already (for instance Visual Studio 2015). To me it also seems likely that it will become part of a future C++ standard (I would assume C++17, but I am not aware of the current status).

这篇关于有一个C ++等同于getcwd吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:32