📄 fillbin.cpp
字号:
//: C25:fillBin.cpp {O}
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Implementation of fillBin()
#include "fillBin.h"
#include "Fillable.h"
#include "../C17/trim.h"
#include "../require.h"
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
void fillBin(string filename, Fillable& bin) {
ifstream in(filename.c_str());
assure(in, filename.c_str());
string s;
while(getline(in, s)) {
int comma = s.find(',');
// Parse each line into entries:
while(comma != string::npos) {
string e = trim(s.substr(0,comma));
// Parse each entry:
int colon = e.find(':');
string type = e.substr(0, colon);
double weight =
atof(e.substr(colon + 1).c_str());
bin.addTrash(
Trash::factory(
Trash::Info(type, weight)));
// Move to next part of line:
s = s.substr(comma + 1);
comma = s.find(',');
}
}
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -