这是我的代码。
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main ( ){
ifstream inFile;
char date1[8], date2[8];
int dayTemp1[24], dayTemp2[24];
inFile.open("weatherdata.txt");
if(inFile.fail()){
cout << "File failed to open.";
exit(1);
}
inFile >> date1 >> date2;
cout << date1 << endl;
cout << date2 << endl;
inFile.close();
return 0;
}
weatherdata.txt 文件的前两行是:
01/04/13
01/05/13
date1 应该包含第一个日期,但在打印时它只打印 '\n' 字符(一个空行)。我不知道代码发生了什么,为什么它跳过了第一个日期行。任何和所有的帮助表示赞赏。我是 C++ 的初学者。