main.cpp
来自「一本语言类编程书籍」· C++ 代码 · 共 37 行
CPP
37 行
// Exercise 19.3a Reading Time class 0bjects from a file.
#include "Time.h"
#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main() {
string fileName;
cout << "\nEnter the name of the file you want to read, including the path: ";
std::getline(cin, fileName);
std::ifstream inFile(fileName.c_str());
if(!inFile) {
cout << "\nFailed to open input file. Program terminated.";
exit(1);
}
Time period;
int count = 0;
cout << "\nTimes on file are: ";
while(!(inFile >> period).eof()) {
if(count++ % 5 == 0)
cout << endl; // Newline every 5th output
cout << period;
}
inFile.close();
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?