简体   繁体   English

Turbo Pascal Assign()函数转换为C ++

[英]Turbo Pascal assign() function to c++

是否有与Turbo Pascal的assign(out f:file, const Name)函数类似的功能,该功能在c ++中为文件分配名称而无需打开文件?

Pascal has an older language construct where you “bind” identifiers to external system resources. Pascal具有较旧的语言构造,您可以在其中将标识符“绑定”到外部系统资源。 Borland (Turbo Pascal) never really implemented the concept beyond what you find in the file access routines. Borland(Turbo Pascal)从未真正实现超出文件访问例程中所见概念的概念。

Most modern languages follow the C-style methodology, in large part because almost all modern operating systems follow the Unix-style file/character device/etc design. 大多数现代语言都遵循C风格的方法,这在很大程度上是因为几乎所有现代操作系统都遵循Unix风格的文件/字符设备/等设计。

Either way, ask yourself what exactly you are trying to accomplish, then figure out how to do it using idiomatic C++. 无论哪种方式,请问自己要完成的任务到底是什么,然后找出如何使用惯用的C ++做到这一点。 The C++ way really is more straightforward. C ++的方法确实更直接。

As you can see , C++ does not have a way in the standard library to create a file stream, give it a file name and then open it. 如您所见 ,C ++在标准库中没有办法创建文件流,给它一个文件名然后打开它。 The open action uses a file name. 打开操作使用文件名。

You can create an file stream that is not open yet, but it won't have a file name. 您可以创建一个尚未打开的文件流,但是它没有文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM