【发布时间】:2015-04-11 17:27:06
【问题描述】:
我目前正在尝试理解从文件中读取一般数据,但是在这种情况下,我正在尝试从 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:\Users\Koolaid Lips\Documents\Visual Studio 2013\Projects\Project2\Debug\Project2.exe'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Cannot find or open the PDB file.
The program '[6584] Project2.exe' has exited with code 0 (0x0).
【问题讨论】:
-
我能解释一下否决票吗?
-
您的代码似乎没有任何问题。您看到有关 PDB 文件的警告的窗口不是显示程序输出的位置。尝试在
main中的最后一个}上设置断点,这样可以防止控制台在程序退出之前关闭。 -
感谢您的评论,但究竟什么是断点?你的意思是像系统(“暂停”)?