我正在尝试创建一个包含两个整数元组的向量,并从文本文件中获取这些整数。为了确保我拥有想要的向量,我尝试打印我的内容,但输出没有显示任何内容。我不确定是因为我的代码还是因为我放置文本文件的位置。我现在被卡住了。如果有任何帮助,我会非常感激。谢谢。
using namespace std;
int main()
{
ifstream file("source.txt");
typedef vector<tuple<int, int>> streets;
streets t;
int a, b;
if (file.is_open())
{
while (((file >> a).ignore() >> b).ignore())
{
t.push_back(tuple<int, int>(a, b));
for (streets::const_iterator i = t.begin();i != t.end();++i)
{
cout << get<0>(*i) << endl;
cout << get<1>(*i) << endl;
}
cout << get<0>(t[0]) << endl;
cout << get<1>(t[1]) << endl;
}
}
file.close();
system("pause");
return 0;
这是我的文本文件和它的位置。 查看图片描述 如果需要,这是我的调试输出结果。 查看调试输出
file.is_open()
返回的是true
吗? - BobMorane