问题标签 [ifstream]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 我什么时候停止读取文件?
some_file.good()
在从文件中读取最后一个条目之后返回false
,还是在尝试读取之后返回?也就是说,我应该写
或者
?
c++ - 无法读取使用 ifstream 加载的文件
我正在加载的文件存在,还有什么问题?paths_in.good 一直失败。
编辑:我想通了。哇,我对这个答案感到恼火。基本上,Windows 让您说出是否要显示文件扩展名。此 Windows 安装设置为不应显示扩展名。因此,当我一次又一次地检查文件时,我看到: directory.txt 并认为这意味着目录的一切都很好,而实际上文件名是 directory.txt.txt
c++ - 在 C++ 中加载文件,设置了故障位,我不知道为什么
可能重复:
无法读取使用 ifstream 加载的文件
以下文件的输出是:00100。这表明我设置了故障位。问题是我无法弄清楚为什么要设置它。有人有一些见解可以分享吗?
编辑:我想通了。哇,我对这个答案感到恼火。基本上,Windows 让您说出是否要显示文件扩展名。此 Windows 安装设置为不应显示扩展名。因此,当我一次又一次地检查文件时,我看到: directory.txt 并认为这意味着目录的一切都很好,而实际上文件名是 directory.txt.txt
c++ - ifstream 的 eof() 是如何工作的?
我真的对eof()
功能感到困惑。假设我 ex.txt 的内容是:
它总是读取一个额外的字符并-1
在使用读取时显示eof()
。但是inf >> c
给出了正确的输出是'abc'?谁能帮我解释一下?
c++ - C# Equivalent to ifstream/ofstream in C++
I know this has probably been asked before, but I can't find it here on SO anywhere, and I can't get a clear answer on anything I look up on Google either.
I need to know the C# equivalent to C++'s ifstream/ofstream.
For instance, if I had the following C++ code:
What would be the C# equivalent?
I found a site that said (for the in file portion, anyway) that the equivalent was this:
I tried putting this in:
I don't have the "FileMode" in mine because VS didn't recognize it. And "input" is a string in the parameters that holds the string value of the input file name (for example - "myFile.txt").
I know I've got to be missing something silly and minor, but I can't figure out what that is. Any help on this would be much appreciated!
I'm developing in VS2010, C#-4.0, WPF API.
c++ - C++:ifstream::getline 问题
我正在阅读这样的文件:
仅出于测试目的,我的文件只有一行,末尾有一个空格:
我的代码首先成功读取了 12345。但随后不是循环结束,而是读取另一个字符串,这似乎是一个返回/换行符。
我已将我的文件保存gedit
在nano
. 而且我也用linuxcat
命令输出过,最后没有返回。所以文件应该没问题。
为什么我的代码读取返回/换行符?
谢谢。
c++ - istream::getline 返回类型
istream::getline
方法返回什么?
我之所以问是因为我已经看到要遍历文件,应该这样做:
什么被退回?
c++ - 使用 ifstream 作为 fscanf
假设我有如下输入:
其中 N、X_i 和 Y_i 是整数。
一个例子:
要阅读这篇文章,我可以这样做(假设所有变量都已定义,等等):
问题是,如何使用 ifstream 轻松做到这一点。我可以得到字符串,然后我可以摆脱非数字并使用字符串流我可以得到两个数字,但这似乎有点麻烦。有没有更简单、更优雅的方法?
谢谢
c++ - 从 ifstream 继承
我可以从 ifstream 继承并从我的派生类中读取文件,如下所示:
我希望它读取整个文件,但它只读取一个符号(这不是给定文件的第一个符号)......
c++ - Open 方法仅打开具有完整路径的文件 C++
如果我写完整路径(完整路径/roots.txt),文件将打开。如果我只写文件名(roots.txt),文件将无法打开
然而,roots.txt 与 main.cpp 位于同一文件夹中。我应该在 XCode 上检查任何设置吗?
这是代码: