Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- error C2664: 'void (int,int,std::ofstream &)' : cannot convert argument 3 from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'std::ofstream &'.
- void writePrimesToFile(int begin, int end, ofstream& file)
- {
- int i, j, prime = 1;
- for (i = begin; i <= end; i++)
- {
- for (j = begin; i <= end / 2; j++)
- {
- if (i % j == 0)
- {
- prime = 0;
- }
- else
- {
- file << i << endl;
- }
- }
- }
- }
- void callWritePrimesMultipleThreads(int begin, int end, string filePath, int N)
- {
- double startTimer, stopTimer;
- startTimer = clock();
- thread* arr = new thread[N];
- for (int i = 0; i < N; i++)
- {
- int start = begin;
- int finish = N;
- arr[i] = thread(writePrimesToFile, start, finish, ref(filePath));
- start = finish;
- finish += N;
- }
- for (int i = 0; i < N; i++)
- {
- arr[i].join();
- }
- stopTimer = clock();
- cout << "The time that takes is: " << double(stopTimer - startTimer) / CLOCKS_PER_SEC << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement