什么是“硬编码"?意思是? [英] What does "hard coded" mean?

查看:1068
本文介绍了什么是“硬编码"?意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的作业要求我访问test.txt文档,因此文件名必须硬编码到我的C驱动器中.我不知道硬编码是什么意思.有人可以帮我吗?

My assignment asks me to access a test.txt document, so the file name has to be hard coded to my C drive. I have no idea what hardcoding means. Can somebody please help me with this?

推荐答案

硬编码"是指在源代码中添加一些内容.如果您不是 硬编码,则可以执行类似提示用户输入数据的操作,或允许用户将数据放在命令行中之类的操作.

"hard coding" means putting something into your source code. If you are not hard coding, then you do something like prompting the user for the data, or allow the user to put the data on the command line, or something like that.

因此,要将文件的位置硬编码为C:驱动器,只需将文件的路径名放在源代码中即可.

So, to hard code the location of the file as being on the C: drive, you would just put the pathname of the file all together in your source code.

这里是一个例子.

int main()
{
    const char *filename = "C:\\myfile.txt";

    printf("Filename is: %s\n", filename);
}

文件名被硬编码"为:C:\myfile.txt

The file name is "hard coded" as: C:\myfile.txt

反斜杠加倍的原因是因为反斜杠在C字符串中是特殊的.

The reason the backslash is doubled is because backslashes are special in C strings.

这篇关于什么是“硬编码"?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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