-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileio.cpp
More file actions
40 lines (34 loc) · 1.02 KB
/
fileio.cpp
File metadata and controls
40 lines (34 loc) · 1.02 KB
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
// basic file io.
// script reads a file line by line, tokenizes by tab, prints first two
// columns to an output file.
// input args: 1) input file 2) output file.
// To compile:
// g++ -I/opt/local/include -L/opt/local/lib fileio.cpp
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
using namespace std;
using namespace boost;
int main (int argc, char* argv[]) {
// I/O
ifstream in; ofstream out;
in.open(argv[1]);
out.open(argv[2]);
const int MAX_LINELEN=1000;
char line1[MAX_LINELEN];
while (in.good())
{
in.getline(line1, MAX_LINELEN);
if (std::strcmp(line1,"") > 0){ // if not empty
vector<string> t1; // tokenize read line.
boost::split(t1, line1, boost::is_any_of("\t"));
int next = boost::lexical_cast<int>(t1[1]); next++;
out << t1[0] << "\t" << t1[1] << endl;
}
}
in.close();out.close();
return 0;
}