Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. 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 &'.
  2.  
  3. void writePrimesToFile(int begin, int end, ofstream& file)
  4. {
  5. int i, j, prime = 1;
  6.  
  7. for (i = begin; i <= end; i++)
  8. {
  9. for (j = begin; i <= end / 2; j++)
  10. {
  11. if (i % j == 0)
  12. {
  13. prime = 0;
  14. }
  15. else
  16. {
  17. file << i << endl;
  18. }
  19. }
  20.  
  21. }
  22.  
  23. }
  24.  
  25. void callWritePrimesMultipleThreads(int begin, int end, string filePath, int N)
  26. {
  27. double startTimer, stopTimer;
  28.  
  29. startTimer = clock();
  30. thread* arr = new thread[N];
  31. for (int i = 0; i < N; i++)
  32. {
  33. int start = begin;
  34. int finish = N;
  35. arr[i] = thread(writePrimesToFile, start, finish, ref(filePath));
  36. start = finish;
  37. finish += N;
  38. }
  39. for (int i = 0; i < N; i++)
  40. {
  41. arr[i].join();
  42. }
  43. stopTimer = clock();
  44. cout << "The time that takes is: " << double(stopTimer - startTimer) / CLOCKS_PER_SEC << endl;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement