Utils_1.cpp
上传用户:speoil
上传日期:2021-10-06
资源大小:100k
文件大小:1k
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <iostream.h>
- #include <fstream.h>
- #include <ctype.h>
- #include <wchar.h>
- #include "Utils_1.h"
- ////////////////////////////////////////////////////////////////////////////
- //
- // Cout
- //
- ////////////////////////////////////////////////////////////////////////////
- reportbuf ReportBuf;
- ostream ReportOut(&ReportBuf);
- ////////////////////////////////////////////////////////////////////////////
- //
- // General purpose functions
- //
- ////////////////////////////////////////////////////////////////////////////
- inline BOOLEAN is_double_digit(int c)
- {
- return (isdigit(c) || (c == '.') || (c == '-') || (c == '+') || (c == 'e'));
- }
- ifstream &operator>>(ifstream &file, double &d)
- {
- static char buffer[100];
- int i = 0;
- while (!is_double_digit(file.peek()))
- file.get();
- do
- file >> buffer[i++];
- while(is_double_digit(file.peek()));
- buffer[i] = ' ';
- d = atof(buffer);
- return file;
- }
- ifstream &operator>>(ifstream &file, int &num)
- {
- static char buffer[100];
- int i = 0;
- while (!is_double_digit(file.peek()) || (file.peek() == 'e'))
- file.get();
- do
- file >> buffer[i++];
- while(is_double_digit(file.peek()));
- buffer[i] = ' ';
- num = atoi(buffer);
- return file;
- }
- int uniform_random(int p_max)
- // Returns an integer between 0 and p_max - 1
- {
- return (int)floor(my_rand() * (double)p_max);
- }