30 int main(
int argc,
char const *argv[])
38 const std::string full_path_exec{argv[0]};
39 std::string::size_type found = full_path_exec.find_last_of(
"/\\", std::string::npos);
40 const std::string exec_path = full_path_exec.substr(0, found);
41 const std::string exec_filename = full_path_exec.substr(found + 1, std::string::npos);
42 const std::string data_file_name(
"\\ch8_5.result");
45 std::string data_file_full_path{exec_path + data_file_name};
46 std::ofstream fout(data_file_full_path.c_str(), std::ios_base::app);
49 std::cerr <<
"无写权限,测试数据文件生成失败!\n";
56 timeinfo = localtime(&rawtime);
58 std::cout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
59 fout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
64 std::vector<size_t> vec;
70 size_t low{10}, high{25}, num_of_points{3};
72 for (
size_t i = 0; i < num_of_points; ++i)
74 iSecret = low + (high - low + 1) * rand() / (RAND_MAX + 1);
75 vec.push_back(iSecret);
78 catch (
const std::string &e)
80 std::cerr << e <<
'\n';
83 catch (
const std::exception &e)
85 std::cerr << e.what() <<
'\n';
86 fout << e.what() <<
'\n';
92 std::cout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
93 fout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";