从文件中读取整数并存储在数组中
Reading integers from a file and storing in an array
我目前正在尝试了解从文件中读取数据的一般情况,但是在这种情况下,我正在尝试从txt文件中读取7个整数并将它们存储在数组中。到目前为止,我拥有的代码如下所示。
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
int arr[7];
ifstream File;
File.open("example.txt");
for (int a = 0; a < 7; a++)
{
File >> arr[a];
}
for (int i = 0; i < 7; i++)
{
cout << arr[i] << " ";
}
}
我从调试器获得的输出如下所示。我认为这是因为它根本无法打开文件,所以我查找了它并发现 txt 文件应该放在工作目录中。我不确定这到底是什么意思,所以我实际上把它放在项目文件夹的每个文件夹中,但我仍然收到同样的错误。提前感谢任何帮助!
'Project2.exe' (Win32): Loaded 'C:UsersKoolaid LipsDocumentsVisual Studio 2013ProjectsProject2DebugProject2.exe'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:WindowsSysWOW64ntdll.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:WindowsSysWOW64kernel32.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:WindowsSysWOW64KernelBase.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:WindowsSysWOW64msvcp120d.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:WindowsSysWOW64msvcr120d.dll'. Cannot find or open the PDB file.
The program '[6584] Project2.exe' has exited with code 0 (0x0).
我运行了您的代码,结果在 Dev-C++ 编译器中还可以。也许您可以更改代码的编译器。这是PDB文件信息,似乎您可以忽略错误消息。
程序数据库 (PDB) 文件包含调试和项目状态信息,这些信息允许对程序的调试配置进行增量链接。使用/ZI 或/Zi 编译 C/C++ 程序或使用/debug 编译 Visual Basic/C#/JScript .NET 程序时,将创建 PDB 文件。
相关文章:
- 使用无符号字符数组有效存储内存
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 在c++中获取两个大int,并将它们存储在数组中
- 使用 Xcode 将双精度存储在数组C++中
- 访问表示 2D 矩阵的 1D 存储数组
- 从输入文件读取整数,仅存储数组C 中的唯一整数
- 如何在队列中存储数组
- 按列主要顺序迭代行大量存储数组
- 如何使存储数组的二进制搜索稳定
- 将行中的字段从textfile中更改为存储数组,而不是重新编写文件
- 存储数组索引值C++
- 存储数组的地方,如果我在返回后声明它
- 缺少存储数组地址的内存
- 使用static在函数中存储数组各个组件的值
- 如何存储数组的每个相邻子数组的和
- 在c++中存储数组映射
- 存储数组的地址列表,以解析原始的非终止文本
- 用于存储数组的字符串
- c++存储数组下一个位置的地址
- 在 for 循环中创建和存储数组