-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.c++
43 lines (32 loc) · 984 Bytes
/
Util.c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Util.c++
// Tech1
//
// Created by Justin Hust on 12/15/13.
// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Util.h"
// -----------------------------------------------------------
std::string string_fromStream(std::ifstream &ifs) {
std::string s((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
return s;
}
// -----------------------------------------------------------
void string_toLower(std::string &s) {
for(unsigned int i=0; i < s.length(); i++) {
char c = s[i];
if(c >= 'A' && c <= 'Z')
s[i] += 32;
}
}
// -----------------------------------------------------------
int random_int(int min, int max) {
return rand() % (max - min) + min;
}
// -----------------------------------------------------------
float random_float(float min, float max) {
return(min + (float)rand() / ((float)RAND_MAX / ( max - min )));
}