forked from vicentebolea/scheduling-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdin_reader.cc
More file actions
38 lines (32 loc) · 767 Bytes
/
Copy pathstdin_reader.cc
File metadata and controls
38 lines (32 loc) · 767 Bytes
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
#include "stdin_reader.hh"
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace scheduler_simulator;
using namespace std;
StdinReader::StdinReader() {
fseek(stdin, 0L, SEEK_SET);
}
//! Interesting method to find if we
//! are about to reach EOF
bool StdinReader::is_next() {
char c = fgetc(stdin);
if (c == EOF)
return false;
else {
ungetc(c, stdin);
return true;
}
}
//! Read the next line from stdin
std::vector<std::string> StdinReader::next() {
char line [SCHEDULER_SIMULATOR_INPUT_LINE_LENGTH];
fgets(line, SCHEDULER_SIMULATOR_INPUT_LINE_LENGTH, stdin);
stringstream ss(line);
vector<string> output;
string token;
while (ss >> token)
output.push_back(token);
return output;
}