如何为C ++设置有效地址? [英] how can I make valid address for C++?
本文介绍了如何为C ++设置有效地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想将一个(C:\ Documents and Settings \ All Users \ Documents \ My Pictures \ Sample Pictures \ Sunset.jpg)这样的地址更改为可在c ++代码中使用的有效地址...
我想在某些代码中使用该地址,例如fopen();
请注意,我从用户那里提供了该地址,并且必须在我的程序中对其进行更改
请帮帮我.
感谢
Hi
I want change one address like ( C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg) to valid address for use it in c++ code ...
I want use that address in some code like fopen();
pay attention I give that address from user and must change it in my programm
please help me.
thanks
推荐答案
必须更改"是什么意思?如果用户在对话框中输入地址或直接输入cin
或类似地址,则无需执行任何操作.一个很好的选择是使用常用对话框之一 [ ^ ],然后让用户导航到所需的位置.
What do you mean by "must change it"? If the user types the address into a dialog or direct into cin
or similar then there is nothing you need to do. A good alternative would be to use one of the Common Dialogs[^] and just let the user navigate to the required location.
这是一个有效的地址...唯一需要记住的是,如果您通过字符串以编程方式指定位置,则必须使用''\\ ''表示反斜杠字符(而不是单个斜杠),但是如果从通常已经在此处处理的某些控件中引入地址,则该地址:
That is a valid address... only thing you have to remember is if you programatically specify the location through a string you have to use ''\\'' to indicate a backslash character (instead of a single slash) however if you bring in the address from some control that''s usually already handled there:
CString location = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg";
在任何情况下都不能将立即字符串常量硬编码在软件产品代码中.
您如何维持呢?所有路径应根据您的可执行文件位置和/或配置文件计算.
(所有其他立即数都应变为显式常数或转到资源中.)
或者,按照Richard的建议使用文件对话框.
—SA
There is not situations when the immediate string constant can be hard-coded in a software product code.
How can you maintain that? All paths should be calculated based on your executable file location and/or your configurations file(s).
(All other immediate constants should became explicit constants or go to resources.)
Alternatively, use file dialogs, as Richard suggested.
—SA
这篇关于如何为C ++设置有效地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文