[try Beta version]
Not logged in

 
printf and cout question

Jul 5, 2012 at 8:13pm
hi,

i have :

1
2
for(int i=0;i<size;i++)
         printf("arr[%3d] = %15.7le\n", i, arr[i]);


which return numbers like the following :

1.0000126e+00


how can i have the same result using cout ??

Thanks !
Jul 6, 2012 at 9:38am
the arr() is double.

when i type it using printf i receive for example
1.0000126e+00
but with cout i receive
1
.. any idea how to solve this ?
Jul 6, 2012 at 9:56am
1
2
for(int i=0;i<size;i++)
	std::cout << "arr[" << std::setw(3) << i << "] = " << std::scientific << std::setw(15) << std::setprecision(7) << arr[i] << "\n";
Last edited on Jul 6, 2012 at 9:58am
Topic archived. No new replies allowed.