如何打开使用相对路径C文件? [英] How do I open a C file with a relative path?

查看:591
本文介绍了如何打开使用相对路径C文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析一个txt文件,我想引用它相对于我目前的目录位置。如果我把文件路径完全将工作,但它我尝试使用
.. \\ SRC \\ test.txt的它不会找到它。这难道不是引用相关文件上一级目录的正确方法?

I am trying to parse a txt file and I want to reference it relative to my current directory location. If I put the file path in completely it will work but it I try to use ..\src\test.txt it wont find it. Is this not the proper way to reference a file relative up one directory?

任何帮助将AP preciated

Any help would be appreciated

推荐答案

如果你把.. \\ SRC \\ test.txt的在一个字符串常量,需要所有的反斜杠使\\ t和 \\的不作为PTED转义序列间$ p $。 (或者你也可以改用正斜线,这是更加便于携带。)

If you put "..\src\test.txt" in a string constant, you need to double all the backslashes so that "\t" and "\s" are not interpreted as escape sequences. (Or you can use forward slashes instead, which is more portable.)

这篇关于如何打开使用相对路径C文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆