the first character of my output is getting cut off?

Ok so I am doing homework and they want me to use a clock to tell the difference in speed when using cout vs printf. They provided me with code to start and every time I run there code I get this. I put it into two posts because I could not get the whole thing in on screenshot. And I don’t know how to post pictures

http://i.imgur.com/untGg2T.png
http://i.imgur.com/uaaLWl8.png

After some messing around I changed the I<100 to I<10 so it was smaller and easier to work with and I got this

http://i.imgur.com/ivU27Nw.png

So somehow it is deleting the first character of my line ever time it prints. And I don’t understand what is wrong because I didn’t write this my instructor did all I did was include stafx.h so it would run.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;

int main()
{
	double start, stop;
	start = clock();
	for (int i = 0; i<100; i++)
	{
		cout << " The number is " + i << endl;
	}

	stop = clock();
	cout << "It took " << (double(stop - start) / CLOCKS_PER_SEC) << " seconds for cout" << endl;
	cin.ignore();
}
Your code should be :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;

int main()
{
	double start, stop;
	start = clock();
	for (int i = 0; i<100; i++)
	{
		cout << " The number is " <<  i << endl;
	}

	stop = clock();
	cout << "It took " << (double(stop - start) / CLOCKS_PER_SEC) << " seconds for cout" << endl;
	cin.ignore();
}

Thank you so very much you are a lifesaver.
Topic archived. No new replies allowed.