📄 datagen.cpp
字号:
//: C05:Datagen.cpp
// From "Thinking in C++, 2nd Edition, Volume 2"
// by Bruce Eckel & Chuck Allison, (c) 2001 MindView, Inc.
// Available at www.BruceEckel.com.
// Test data generator
//{L} Datalog ../TestSuite/Test
#include "DataLogger.h"
#include "../require.h"
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
ofstream data("data.txt");
assure(data, "data.txt");
ofstream bindata("data.bin", ios::binary);
assure(bindata, "data.bin");
time_t timer;
// Seed random number generator:
srand(time(&timer));
for(int i = 0; i < 100; i++) {
DataPoint d;
// Convert date/time to a structure:
d.setTime(*localtime(&timer));
timer += 55; // Reading each 55 seconds
d.setLatitude("45*20'31\"");
d.setLongitude("22*34'18\"");
// Zero to 199 meters:
double newdepth = rand() % 200;
double fraction = rand() % 100 + 1;
newdepth += double(1) / fraction;
d.setDepth(newdepth);
double newtemp = 150 + rand()%200; // Kelvin
fraction = rand() % 100 + 1;
newtemp += (double)1 / fraction;
d.setTemperature(newtemp);
d.print(data);
bindata.write((const char*)&d, sizeof(d));
}
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -