使用fstream从文件中读取多个值? [英] Read multiple values from file with fstream?

查看:116
本文介绍了使用fstream从文件中读取多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用制表符分隔的文本文件读取多个值吗

Can I read multiple values from tab separated text file with

double value1, value2, value3;
ifstream in;
fin.open ("myfile.dat", ifstream::in);
fin >> value1 >> value2 >> value3;

我所有值都为零.

推荐答案

好的,在您的代码中存在三个重要错误:

Ok, in your code there are three important mistakes:

    在此范围内未声明
  • fin(您可能需要将第二行的in更改为fin)
  • ofstream::in不存在,您可能是说fstream::in
  • 您还应该确保输入文件存在.这可以通过fin.good()
  • 完成
  • fin was not declared in this scope (you probably need to change the in at the second line to fin)
  • ofstream::in does not exist, you probably mean fstream::in
  • you should also make sure that your input file exist. This can be done with fin.good()

这篇关于使用fstream从文件中读取多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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