1// endl example
2#include <iostream> // std::cout, std::end
3using namespace std;
4int main () {
5
6 int a=100;
7 double b=3.14;
8
9 cout << a;
10 cout << endl; // manipulator inserted alone
11 cout << b << endl << a*b; // manipulator in concatenated insertion
12 endl (cout); // endl called as a regular function
13
14 return 0;
15}
1#include <iostream>
2#include <chrono>
3
4template<typename Diff>
5void log_progress(Diff d)
6{
7 std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(d).count()
8 << " ms passed" << std::endl;
9}
10
11int main()
12{
13 std::cout.sync_with_stdio(false); // on some platforms, stdout flushes on \n
14 volatile int sink = 0;
15
16 auto t1 = std::chrono::high_resolution_clock::now();
17 for (int j=0; j<5; ++j)
18 {
19 for (int n=0; n<10000; ++n)
20 for (int m=0; m<20000; ++m)
21 sink += m*n; // do some work
22 auto now = std::chrono::high_resolution_clock::now();
23 log_progress(now - t1);
24 }
25}
1cout << "Hello " << '\n'<<"world";
2cout << "Hello " << endl<<"world";
3//Hello
4//world