-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kobyshev S(tools4brokers).cpp
48 lines (42 loc) · 1.19 KB
/
Kobyshev S(tools4brokers).cpp
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
44
45
46
47
// Kobyshev S(tools4brokers).cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <fstream>
#include <boost\thread.hpp>
#include <boost\filesystem.hpp>
static int sum = 0;
void file_check(std::string path){
std::ostringstream buffer;
try{
int tmp = 0;
std::ifstream input_file(path);
input_file>>tmp;
input_file.close();
sum += tmp;
buffer<<path.substr(path.find_last_of("\\")+1)<<": "<<tmp<<std::endl;
}catch(std::exception e){
buffer<<"Error with "<<path<<std::endl;
}
std::cout<<buffer.str();
boost::this_thread::sleep_for(boost::chrono::seconds(1));
}
int _tmain(int argc, _TCHAR* argv[])
{
if(argc == 1){
std::cout<<"Error! Enter file paths as parameters."<<std::endl;
return 1;
}
boost::thread_group all_threads; // or we can use std::list<boost::thread> all_threads;
boost::filesystem::directory_iterator end;
for(int i=1; i<argc; i++)
{
for(boost::filesystem::directory_iterator i(argv[i]);i != end; i++)
if (boost::filesystem::is_regular_file(i->path()))
{
all_threads.add_thread(new boost::thread(file_check,i->path().string()));
}
}
all_threads.join_all();
std::cout<<"Total sum: "<<sum<<std::endl;
return 0;
}