如何从ifstream打印文件名? [英] how to print a filename from ifstream?

查看:359
本文介绍了如何从ifstream打印文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有谁能告诉我如何从ifstream打印文件名?


以下cout代码无法打印我用

ifstream创建的文件名:@ />

ifstream是;

is.open(" text.txt");


cout<< ifstream中的文件名: <<是<< endl;


Sam。

Hi,

Can anyone tell me how to print a file name from ifstream?

the following cout code does not print the filename I created with
ifstream preivous:

ifstream is;
is.open ("text.txt");

cout << "filename in ifstream: " << is << endl;

Sam.

推荐答案

你觉得你不觉得有点傻吗? br />
如果你知道一个流的名字我设计时只需打印它就像

cout<<" name";


如果你不知道它你必须在变量中拥有它吗?

在这种情况下使用cout<< variable;


-

SirMike

代码是我的力量
http://www.sirmike.grudziadz.com
Don''t you think is a little bit stupid ?
If you know the name of a stream i design-time simply print it like
cout<<"name";

If you don''t know it you must have it in a variable haven''t you ?
In this case use cout<<variable;

--
SirMike
the code is my strength
http://www.sirmike.grudziadz.com


sam写道:
谁能告诉我如何从ifstream打印文件名?


不。没人能。 ifstream不保留该信息。

[..]
Can anyone tell me how to print a file name from ifstream?
Nope. Nobody can. ifstream does not retain that information.
[..]




V



V


我不知道它是否会对你有所帮助,

但是如果它对你有用,你可以这样做:

String FileName;

FileName =" text.txt";

cout<<" filename ..."<<< FileName<< endl;

但是就像SirMike对你说的那样

I don''t know if it will help you,
but if it okfor you you can do like that:
String FileName;
FileName="text.txt";
cout <<"filename ..."<<FileName<<endl;
but it is the same like SirMike said to you


这篇关于如何从ifstream打印文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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