在运行时构造文件名字符串 [英] constructing filename string at runtime
本文介绍了在运行时构造文件名字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要打开一个文件,其名称我只知道运行时的一部分。
它基于char值。
char代表性别并且是''m''或'''''''
i需要从名为names_m.txt或names_f.txt的文本文件加载,但我不是知道直到运行时。
i尝试了这个,但它没有完全奏效...
展开 | 选择 | 换行 | 行号
解决方案
你可以使用类似sprintf()函数的东西。
我认为t格式化字符串,如printf,而不是打印它们,它将字符串保存在变量中。
在MSDN中查找更多信息。
我认为它有点帮助你。
实际上我经历了它,问题似乎在/ data /中。 part ...我访问文件的方式有问题...
我需要访问工作目录中的数据文件夹
我会使用一个字符串作为变量(由于某些原因你不能这样做)。
展开 | 选择 | Wrap | 行号
i need to open a file whose name i only know part of until runtime.
it is based on a char value.
the char represents gender and is either ''m'' or ''''f''
i need to load from a text file called names_m.txt or names_f.txt but i don''t know until runtime.
i tried this but it didnt quite work...
Expand|Select|Wrap|Line Numbers解决方案You couls use something like the sprintf() function.
I think that formats strings like printf except instead of printing them, it saves the string in a variable.
Look it up in MSDN for more info.
I think it mite help u.
actually i ran through it and the problem seems to be in the "/data/" part...is there something wrong with the way i access the file...
like i need to access the folder ''data'' in the working directory
I would use a string as a variable (are you unable to do this for some reason).
Expand|Select|Wrap|Line Numbers
这篇关于在运行时构造文件名字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆