【发布时间】:2015-12-30 07:02:20
【问题描述】:
所以我正在尝试从文本文件中读取。它表明我可以成功地从文件中读取但是当我尝试计算这些值时,它只显示 0,而我在文本文件中有其他值。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
std::ifstream file("numbers.txt");
if (file) {
cout << "Managed to read file successfully. \n";
}else{
cout << "Unable to read file.";
}
int x, y;
file >> x >> y;
cout << "Num 1: " << x << endl;
cout << "Num 2: " << y << endl;
return 0;
}
【问题讨论】:
-
请显示文件内容。
-
当您打印
Managed to read file successfully时,您还没有从文件中读取任何内容。你所做的就是打开它。 -
为什么这个问题听起来像stackoverflow.com/questions/34489267/… 和stackoverflow.com/questions/34486953/… 如此诡异?现在有网课吗?