I want to set a specific precision in a float number. So I found the public member function "std::ios_base::precision" and did a small exercise that worked correctly:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
usingnamespace std;
int main() {
double f=3.14159;
cout.precision(10);
cout.setf(ios::fixed, ios::floatfield);
cout<<f<<endl; //cout displays 10 numbers after the comma
return 0;
}
Everything you did is correct, and it compiled just fine to me, but i had to first set the flag of
-std=c++11, because one of your libraries requires so, Other than that, it compiled just fine for me, i don't know what issue you have there.
I also set the flag "-std=c++11" but I still have the error. @masecla33 It is strange that for you is working. I wonder what it can be wrong with my compilation...
#include <iostream>
#include <chrono>
#include <thread>
#include <iomanip> //for me it compiled just fine without this tough i added just to be sure
usingnamespace std;
//Prototypes
void f();
int main() {
clock_t c_start=clock();
auto t_start=chrono::high_resolution_clock::now();
thread t1(f);
thread t2(f);
t1.join();
t2.join();
clock_t c_end=clock();
auto t_end=chrono::high_resolution_clock::now();
//cout.unsetf(ios::floatfield);
cout.precision(2); //The compiler complains at this line
cout.setf(ios::fixed, ios::floatfield);
cout<<"CPU time used"<< 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " ms\n";
return 0;
}
void f(){
volatiledouble d=0;
for(int n=0;n<10000;n++){
for(int m=0; m<10000; m++){
d += d*n*m;
}
}
}
Try making another project with the same code and stuff.