所以我想从文本文件中读取。它表明我可以成功从文件中读取但是当我尝试关闭值时,它只显示0,而我在文本文件中有其他值。用ifstream从文本文件中读取
#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;
}
请显示文件内容。 – Barmar
当您打印'管理成功读取文件'时,您没有从文件中读取任何内容。你所做的只是打开它。 – Barmar
为什么这个问题听起来如此怪异的像http://stackoverflow.com/questions/34489267/how-to-read-data-from-files-in-turbo-c-4-0和http://stackoverflow.com/questions/34486953/how-to-read-numbers-on-text-files-using-turbo-c-4-0?现在有线上课了吗? –